制作符合自己需求的镜像 docker image
常用命令
镜像列表
docker images
malijun@MaLiJun-Ubuntu:~/workdir/dockerpro/bitmexpro$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE bitmex 0.0.1 2fa73485f763 3 weeks ago 958MB bitmexpro 0.1 e49942b750bf 4 weeks ago 1.19GB python 3.6 a6ce22fd0733 4 weeks ago 912MB mongo 3.6 87f1a6e84e00 4 weeks ago 368MB mongo latest 87f1a6e84e00 4 weeks ago 368MB ubuntu latest 113a43faa138 4 weeks ago 81.1MB debian wheezy 4c3b65fb373e 2 months ago 88.3MB hello-world latest e38bc07ac18e 2 months ago 1.85kB training/webapp latest 6fae60ef3446 3 years ago 349MB
查找镜像
docker search name
malijun@MaLiJun-Ubuntu:~/workdir/dockerpro/bitmexpro$ docker search ubuntu NAME DESCRIPTION STARS OFFICIAL AUTOMATED ubuntu Ubuntu is a Debian-based Linux operating sys… 7917 [OK] dorowu/ubuntu-desktop-lxde-vnc Ubuntu with openssh-server and NoVNC 193 [OK] rastasheep/ubuntu-sshd Dockerized SSH service, built on top of offi… 156 [OK] ansible/ubuntu14.04-ansible Ubuntu 14.04 LTS with ansible 93 [OK] ubuntu-upstart Upstart is an event-based replacement for th… 87 [OK] neurodebian NeuroDebian provides neuroscience research s… 50 [OK] ubuntu-debootstrap debootstrap --variant=minbase --components=m… 38 [OK] 1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 36 [OK] nuagebec/ubuntu Simple always updated Ubuntu docker images w… 23 [OK] tutum/ubuntu Simple Ubuntu docker images with SSH access 18 i386/ubuntu Ubuntu is a Debian-based Linux operating sys… 13 ppc64le/ubuntu Ubuntu is a Debian-based Linux operating sys… 12 1and1internet/ubuntu-16-apache-php-7.0 ubuntu-16-apache-php-7.0 10 [OK] 1and1internet/ubuntu-16-nginx-php-phpmyadmin-mariadb-10 ubuntu-16-nginx-php-phpmyadmin-mariadb-10 6 [OK] eclipse/ubuntu_jdk8 Ubuntu, JDK8, Maven 3, git, curl, nmap, mc, … 6 [OK] codenvy/ubuntu_jdk8 Ubuntu, JDK8, Maven 3, git, curl, nmap, mc, … 4 [OK] darksheer/ubuntu Base Ubuntu Image -- Updated hourly 4 [OK] 1and1internet/ubuntu-16-apache ubuntu-16-apache 3 [OK] 1and1internet/ubuntu-16-nginx-php-5.6-wordpress-4 ubuntu-16-nginx-php-5.6-wordpress-4 3 [OK] 1and1internet/ubuntu-16-sshd ubuntu-16-sshd 1 [OK] pivotaldata/ubuntu A quick freshening-up of the base Ubuntu doc… 1 1and1internet/ubuntu-16-healthcheck ubuntu-16-healthcheck 0 [OK] pivotaldata/ubuntu-gpdb-dev Ubuntu images for GPDB development 0 smartentry/ubuntu ubuntu with smartentry 0 [OK]
获取新镜像
docker pull name
malijun@MaLiJun-Ubuntu:~/workdir/dockerpro/bitmexpro$ docker pull ubuntu Using default tag: latest latest: Pulling from library/ubuntu Digest: sha256:5f4bdc3467537cbbe563e80db2c3ec95d548a9145d64453b06939c4592d67b6d Status: Image is up to date for ubuntu:latest
运行镜像生成容器, 进入镜像(更多容器操作在 https://www.cnblogs.com/maxiaohei/p/9267608.html)
malijun@MaLiJun-Ubuntu:~/workdir/dockerpro/bitmexpro$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE bitmex 0.0.1 2fa73485f763 3 weeks ago 958MB <none> <none> 64f844a4e9f4 3 weeks ago 912MB <none> <none> a6af3caedaf1 3 weeks ago 912MB <none> <none> cb27a6f56c3a 3 weeks ago 89MB bitmexpro 0.1 e49942b750bf 4 weeks ago 1.19GB python 3.6 a6ce22fd0733 4 weeks ago 912MB mongo 3.6 87f1a6e84e00 4 weeks ago 368MB mongo latest 87f1a6e84e00 4 weeks ago 368MB ubuntu latest 113a43faa138 4 weeks ago 81.1MB debian wheezy 4c3b65fb373e 2 months ago 88.3MB hello-world latest e38bc07ac18e 2 months ago 1.85kB training/webapp latest 6fae60ef3446 3 years ago 349MB malijun@MaLiJun-Ubuntu:~/workdir/dockerpro/bitmexpro$ docker run -it ubuntu /bin/bash root@3a910bf167ab:/# ls bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var root@3a910bf167ab:/# cat /etc/issue Ubuntu 18.04 LTS \n \l
制作符合自己要求的镜像(重点)
法一:从已有容器中更新镜像,并且提交这个镜像
更新 ubuntu成为自己需要的镜像
1 进入容器 docker run ubuntu
malijun@MaLiJun-Ubuntu:~/workdir/dockerpro/bitmexpro$ docker run -it ubuntu /bin/bash root@3a910bf167ab:/# ls bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var root@3a910bf167ab:/# cat /etc/issue Ubuntu 18.04 LTS \n \l
2 更新系统源 apt-get update
root@3a910bf167ab:/# apt-get update Get:1 http://security.ubuntu.com/ubuntu bionic-security InRelease [83.2 kB] Get:2 http://archive.ubuntu.com/ubuntu bionic InRelease [242 kB] Get:3 http://security.ubuntu.com/ubuntu bionic-security/universe Sources [5645 B] Get:4 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 Packages [1075 B] Get:5 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [39.3 kB] Get:6 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [137 kB] Get:7 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB] Get:8 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB] Get:9 http://archive.ubuntu.com/ubuntu bionic/universe Sources [11.5 MB] Get:10 http://archive.ubuntu.com/ubuntu bionic/restricted amd64 Packages [13.5 kB] Get:11 http://archive.ubuntu.com/ubuntu bionic/main amd64 Packages [1344 kB] Get:12 http://archive.ubuntu.com/ubuntu bionic/multiverse amd64 Packages [186 kB] Get:13 http://archive.ubuntu.com/ubuntu bionic/universe amd64 Packages [11.3 MB] Get:14 http://archive.ubuntu.com/ubuntu bionic-updates/universe Sources [43.6 kB] Get:15 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [217 kB] Get:16 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [140 kB] Get:17 http://archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 Packages [3679 B] Get:18 http://archive.ubuntu.com/ubuntu bionic-backports/universe amd64 Packages [2807 B] Fetched 25.5 MB in 12s (2195 kB/s) Reading package lists... Done
(3 安装python3.6 apt-get install python3.6)
3 退出容器 exit
root@86437e52b5f2:/# exit
exit
4 对更新了系统源的容器,保存为新的image
malijun@MaLiJun-Ubuntu:~/workdir/dockerpro/bitmexpro$ docker commit -m "has update" -a "mlj" 86437e52b5f2 mlj/ubuntu:18.04 sha256:ff7c022e2bb3d70f1f6a09be20f81ac2fab9a6b7b9784ab5e7f0835746f492cf
5 查看更新后的image
malijun@MaLiJun-Ubuntu:~/workdir/dockerpro/bitmexpro$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE mlj/ubuntu 18.04 ff7c022e2bb3 43 seconds ago 122MB (更新后) python 3.6 a6ce22fd0733 4 weeks ago 912MB mongo 3.6 87f1a6e84e00 4 weeks ago 368MB ubuntu latest 113a43faa138 4 weeks ago 81.1MB (更新前) debian wheezy 4c3b65fb373e 2 months ago 88.3MB hello-world latest e38bc07ac18e 2 months ago 1.85kB
法二:使用dockerfile指令创建镜像
1 需要编写Dockerfile文件
2 使用docker build 命令构建镜像
LESS IS MORE !