docker commit命令-提交一个新的image


使用示例

docker commit 12c487801c50 sw-centos-ssh-http:v1.0.0







查看镜像

[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
sw-centos-ssh       v1.0.1              a18e5ad19f04        6 minutes ago       315.2 MB
docker.io/centos    latest              3bee3060bfc8        3 weeks ago         192.5 MB
[root@localhost ~]# 






查看容器

[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE                  COMMAND             CREATED             STATUS                      PORTS                  NAMES
12c487801c50        sw-centos-ssh:v1.0.1   "/usr/sbin/init"    5 minutes ago       Up 5 minutes                0.0.0.0:8031->22/tcp   swtest1
3aee75b07ec2        docker.io/centos       "/bin/bash"         21 minutes ago      Exited (0) 17 minutes ago                          pensive_jones






查看容器12c487801c50的IP

[root@localhost ~]#  docker inspect 12c487801c50 | grep "IPA"
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.2",
                    "IPAMConfig": null,
                    "IPAddress": "172.17.0.2",





远程进入容器

[root@localhost ~]# ssh -l root 172.17.0.2
[root@12c487801c50 ~]# ifconfig






安装httpd

[root@12c487801c50 ~]# yum install httpd -y  
[root@12c487801c50 ~]# vi /etc/httpd/conf/httpd.conf 
[root@12c487801c50 ~]# cat /etc/httpd/conf/httpd.conf 
......
ServerName localhost:80
......
[root@12c487801c50 ~]# 




设置为开启即启动

[root@12c487801c50 ~]# systemctl start httpd    
[root@12c487801c50 ~]# systemctl enable httpd
[root@12c487801c50 ~]# ps aux |grep httpd  
[root@12c487801c50 ~]#  httpd -k stop  
[root@12c487801c50 ~]# httpd
[root@12c487801c50 ~]# ps aux |grep httpd  
[root@12c487801c50 ~]# exit





测试访问

[root@localhost ~]# curl -I 172.17.0.2
[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE                  COMMAND             CREATED             STATUS                      PORTS                  NAMES
12c487801c50        sw-centos-ssh:v1.0.1   "/usr/sbin/init"    12 minutes ago      Up 12 minutes               0.0.0.0:8031->22/tcp   swtest1
3aee75b07ec2        docker.io/centos       "/bin/bash"         28 minutes ago      Exited (0) 25 minutes ago                          pensive_jones
[root@localhost ~]# 





将刚刚的安装好的容器提交为一个新容器

[root@localhost ~]# docker commit 12c487801c50 sw-centos-ssh-http:v1.0.0
[root@localhost ~]# docker images
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
sw-centos-ssh-http   v1.0.0              b9fa9fc7eb88        42 seconds ago      479.2 MB
sw-centos-ssh        v1.0.1              a18e5ad19f04        16 minutes ago      315.2 MB
docker.io/centos     latest              3bee3060bfc8        3 weeks ago         192.5 MB
[root@localhost ~]# 


Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐