[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd latest 2e202f453940 11 days ago 179MB
nginx latest 3f8a4339aadd 5 weeks ago 108MB
hello-world latest f2a91732366c 2 months ago 1.85kB
training/webapp latest 6fae60ef3446 2 years ago 349MB
[root@docker ~]# docker run -ti httpd /bin/bash
root@dd34d7458e86:/usr/local/apache2# ls
bin build cgi-bin conf error htdocs icons include logs modules
root@dd34d7458e86:/usr/local/apache2#
[root@docker ~]# docker search httpd
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
httpd The Apache HTTP Server Project 1490 [OK]
hypriot/rpi-busybox-httpd Raspberry Pi compatible Docker Image with a … 40
centos/httpd 15 [OK]
centos/httpd-24-centos7 Platform for running Apache httpd 2.4 or bui… 8
armhf/httpd The Apache HTTP Server Project 8
macadmins/netboot-httpd use in combination with bruienne/bsdpy 4 [OK]
salim1983hoop/httpd24 Dockerfile running apache config 2 [OK]
lolhens/httpd Apache httpd 2 Server 2 [OK]
rgielen/httpd-image-php5 Docker image for Apache httpd with PHP 5 bas… 1 [OK]
rgielen/httpd-image-simple Docker image for simple Apache httpd based o… 1 [OK]
lead4good/httpd-fpm httpd server which connects via fcgi proxy h… 1 [OK]
fboaventura/dckr-httpd Small footprint http server to use with othe… 1 [OK]
epflidevelop/os-wp-httpd WP httpd 1 [OK]
publici/httpd httpd:latest 0 [OK]
tplatform/aws-linux-httpd24-php70 aws-linux-httpd24-php70 0 [OK]
dockerpinata/httpd 0 5.创建镜像
在生产环境上,一般情况下,docker镜像需要自身业务来定制,可通过两种方式来实现docker镜像的定制化
a.从已有创建的容器镜像更新
b.根据自身需求编写dockerfile创建新镜像
更新镜像前,先使用该镜像创建一个容器
[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd latest 2e202f453940 11 days ago 179MB
ubuntu 16.04 0458a4468cbc 11 days ago 112MB
nginx latest 3f8a4339aadd 5 weeks ago 108MB
hello-world latest f2a91732366c 2 months ago 1.85kB
training/webapp latest 6fae60ef3446 2 years ago 349MB
[root@docker ~]# docker run -ti ubuntu:16.04 /bin/bash
root@7e0559072ced:/#
[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
liu/ubuntu v2 15caed782326 2 minutes ago 151MB ####提交的新镜像
httpd latest 2e202f453940 11 days ago 179MB
ubuntu 16.04 0458a4468cbc 12 days ago 112MB
nginx latest 3f8a4339aadd 6 weeks ago 108MB
hello-world latest f2a91732366c 2 months ago 1.85kB
training/webapp latest 6fae60ef3446 2 years ago 349MB
使用新镜像启动一个容器
[root@docker ~]# docker run -ti liu/ubuntu:v2 /bin/bash
root@60e40fc5e5d8:/#
[root@docker ~]# docker build -t liulei/centos:6.7 .
ERRO[0000] Can't add file /root/.gnupg/S.gpg-agent to tar: archive/tar: sockets not supported
Sending build context to Docker daemon 779.4MB
Step 1/9 : FROM centos:6.7
6.7: Pulling from library/centos
cbddbc0189a0: Pull complete
Digest: sha256:7248c96de4648749c7936f203d983530e7ebdd83c3db6d47278392f18bcd7baf
Status: Downloaded newer image for centos:6.7
---> 000c5746fa52
Step 2/9 : MAINTAINER Fisher "fisher@sudops.com"
---> Running in 7de81283b6be
Removing intermediate container 7de81283b6be
---> 00e92f10a010
Step 3/9 : RUN /bin/echo 'root:123456' |chpasswd
---> Running in e2265b58e93b
Removing intermediate container e2265b58e93b
---> 0bd4ee58d0e3
Step 4/9 : RUN useradd liulei
---> Running in 846595d00078
Removing intermediate container 846595d00078
---> 600139a37c32
Step 5/9 : RUN /bin/echo 'liulei:123456' |chpasswd
---> Running in 236b3202305b
Removing intermediate container 236b3202305b
---> 984723c05b0f
Step 6/9 : RUN /bin/echo -e "LANG=\"en_US.UTF-8\"" >/etc/default/local
---> Running in c18bf04cfb8c
Removing intermediate container c18bf04cfb8c
---> 65c9fe71b1f9
Step 7/9 : EXPOSE 22
---> Running in 93f0491bde21
Removing intermediate container 93f0491bde21
---> 14ee40f132fc
Step 8/9 : EXPOSE 80
---> Running in 5be75fdead2e
Removing intermediate container 5be75fdead2e
---> f380dde783ad
Step 9/9 : CMD /usr/sbin/sshd -D
---> Running in cf4e114e9953
Removing intermediate container cf4e114e9953
---> dc64de0c25c4
Successfully built dc64de0c25c4
Successfully tagged liulei/centos:6.7
[root@docker ~]#
参数说明
-t 表示指定要创建的目标镜像名
. 表示Dokerfile文件在当前目录,也可以指定Dockerfile的绝对路径
使用docker images 查看通过dockerfile文件创建的镜像是否存在
[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
liulei/centos 6.7 dc64de0c25c4 6 minutes ago 191MB ##使用Dockerfile创建的镜像
liu/ubuntu v2 15caed782326 21 minutes ago 151MB
httpd latest 2e202f453940 11 days ago 179MB
ubuntu 16.04 0458a4468cbc 12 days ago 112MB
nginx latest 3f8a4339aadd 6 weeks ago 108MB
hello-world latest f2a91732366c 2 months ago 1.85kB
centos 6.7 000c5746fa52 3 months ago 191MB
training/webapp latest 6fae60ef3446 2 years ago 349MB
使用Dockerfile文件创建的镜像来运行容器
[root@docker ~]# docker run -ti dc64de0c25c4 /bin/bash
[root@c12f3fe4ea60 /]#
7.设置镜像标签
使用docker tag 命令为镜像设置标签
[root@docker ~]# docker tag dc64de0c25c4 liulei/centos:new
[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
liulei/centos 6.7 dc64de0c25c4 13 minutes ago 191MB
liulei/centos new dc64de0c25c4 13 minutes ago 191MB
liu/ubuntu v2 15caed782326 28 minutes ago 151MB
httpd latest 2e202f453940 11 days ago 179MB
ubuntu 16.04 0458a4468cbc 12 days ago 112MB
nginx latest 3f8a4339aadd 6 weeks ago 108MB
hello-world latest f2a91732366c 2 months ago 1.85kB
centos 6.7 000c5746fa52 3 months ago 191MB
training/webapp latest 6fae60ef3446 2 years ago 349MB