1.启动容器
[root@centos201 ~]# docker run --name base -d centos:7 tail -f /etc/hosts
2.安装服务
[root@centos201 ~]# docker exec -it base bash
....
[root@40235cf19d2e /]# curl -s -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@40235cf19d2e /]#
[root@40235cf19d2e /]# curl -s -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@40235cf19d2e /]#
[root@40235cf19d2e /]# yum -y install nginx
[root@40235cf19d2e /]#
[root@40235cf19d2e /]# rm -rf /usr/share/nginx/html/*
[root@40235cf19d2e /]#
[root@40235cf19d2e /]# echo www.oldboyedu.com > /usr/share/nginx/html/index.html
[root@40235cf19d2e /]#
[root@40235cf19d2e /]# nginx -g 'daemon off;' # 在前台启动nginx服务
[root@40235cf19d2e /]#
[root@40235cf19d2e /]# exit
exit
[root@centos201 ~]#
3.将容器提交为镜像
[root@centos201 ~]# docker container commit -a linux86@oldboyedu.com -m 'shou dong v0.1' base oldboyedu-centos-nginx:v0.1 # -a表示声明作者信息,-m表示声明注释信息。
sha256:1b12c02f3eee2cd802232af1a1b0e8d14ae92017bf442a5fefdcbae0053f7bf7
[root@centos201 ~]#
4.查看镜像的详细信息
[root@centos201 ~]# docker inspect oldboyedu-centos-nginx:v0.1
5.手动再次提交测试
[root@centos201 ~]# docker run -d --name myweb01 oldboyedu-centos-nginx:v0.1
421c63c8f77456096438fd7e5c06597b1fc16819db5238c52516369ba3c787b1
[root@centos201 ~]#
[root@centos201 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
421c63c8f774 oldboyedu-centos-nginx:v0.1 "tail -f /etc/hosts" 2 seconds ago Up 1 second myweb01
[root@centos201 ~]#
[root@centos201 ~]#
[root@centos201 ~]#
[root@centos201 ~]# docker run -d --name myweb02 oldboyedu-centos-nginx:v0.1 nginx -g 'daemon off;'
ed611aafcd65a5249993ab00f84d8b27a14830e6e248d525e5ee4be9eff146b1
[root@centos201 ~]#
[root@centos201 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ed611aafcd65 oldboyedu-centos-nginx:v0.1 "nginx -g 'daemon of…" 2 seconds ago Up 1 second myweb02
421c63c8f774 oldboyedu-centos-nginx:v0.1 "tail -f /etc/hosts" 16 seconds ago Up 15 seconds myweb01
[root@centos201 ~]#
[root@centos201 ~]#
[root@centos201 ~]# docker container commit myweb02 oldboyedu-centos-nginx:v0.2
sha256:4cee54a629e82d40b17f4bcf380dce00499baa38caabfdb8b7d2290b4daa0cbc
[root@centos201 ~]#
[root@centos201 ~]# docker run -d --name myweb03 oldboyedu-centos-nginx:v0.2
1fda0fd540088f8d5af23c898f45083877f3fd0be44ce8f8cf174945d13b40de
[root@centos201 ~]#
[root@centos201 ~]#
[root@centos201 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1fda0fd54008 oldboyedu-centos-nginx:v0.2 "nginx -g 'daemon of…" 7 seconds ago Up 7 seconds myweb03
ed611aafcd65 oldboyedu-centos-nginx:v0.1 "nginx -g 'daemon of…" 53 seconds ago Up 53 seconds myweb02
421c63c8f774 oldboyedu-centos-nginx:v0.1 "tail -f /etc/hosts" About a minute ago Up About a minute myweb01
[root@centos201 ~]#
[root@centos201 ~]# docker container inspect -f "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" `docker container ps -lq`
172.17.0.4
[root@centos201 ~]#
[root@centos201 ~]# curl 172.17.0.4
www.oldboyedu.com
[root@centos201 ~]#