首页   快速返回

docker commit命令使用     所属分类 docker
docker commit 可用于定制镜像 ,不建议使用
推荐使用 Dockerfile 定制镜像 

docker run --name nginx -d -p 8080:80 nginx
注意内部端口号是 80  !!!  
8080:80 !!!

curl http://127.0.0.1:8080

netstat -anlp |grep 8080
tcp6       0      0 :::8080                 :::*                    LISTEN      9613/docker-proxy-c 


docker exec -it nginx bash

进入容器的shell

echo 'Hello, Docker!' > /usr/share/nginx/html/index.html
exit

curl http://127.0.0.1:8080
Hello, Docker!


修改了容器的文件,也就是改动了容器的存储层。通过 docker diff 命令看到具体的改动

docker diff nginx
C /root
A /root/.bash_history
C /run
A /run/nginx.pid
A /run/secrets
C /usr
C /usr/share
C /usr/share/nginx
C /usr/share/nginx/html
C /usr/share/nginx/html/index.html
C /var
C /var/cache
C /var/cache/nginx
A /var/cache/nginx/uwsgi_temp
A /var/cache/nginx/client_temp
A /var/cache/nginx/fastcgi_temp
A /var/cache/nginx/proxy_temp
A /var/cache/nginx/scgi_temp



docker commit  将容器的存储层保存下来成为镜像
在原有镜像的基础上,叠加上容器的存储层,构成新的镜像。

docker commit --author "dugang" --message "index.html update" nginx nginx:v2
    
    
docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
nginx                   v2                  27c7bba6e8bf        6 seconds ago       109 MB
docker.io/nginx         latest              53f3fd8007f7        2 days ago          109 MB
docker.io/ubuntu        latest              d131e0fa2585        13 days ago         102 MB
docker.io/hello-world   latest              fce289e99eb9        4 months ago        1.84 kB


docker run --name nginx-v2 -d -p 8090:80 nginx:v2

curl http://127.0.0.1:8090
Hello, Docker!

docker ps 
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
ca638074b505        nginx:v2            "nginx -g 'daemon ..."   30 seconds ago      Up 29 seconds       0.0.0.0:8090->80/tcp   nginx-v2
15a64ee6fdf3        nginx               "nginx -g 'daemon ..."   12 minutes ago      Up 12 minutes       0.0.0.0:8080->80/tcp   nginx


docker image ls nginx
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               v2                  27c7bba6e8bf        2 minutes ago       109 MB
docker.io/nginx     latest              53f3fd8007f7        2 days ago          109 MB


docker history 查看镜像历史记录

docker history nginx:v2



IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
27c7bba6e8bf        3 minutes ago       nginx -g daemon off;                            204 B               index.html update
53f3fd8007f7        2 days ago          /bin/sh -c #(nop)  CMD ["nginx" "-g" "daem...   0 B                 
<missing>           2 days ago          /bin/sh -c #(nop)  STOPSIGNAL SIGTERM           0 B                 
<missing>           2 days ago          /bin/sh -c #(nop)  EXPOSE 80                    0 B                 
<missing>           2 days ago          /bin/sh -c ln -sf /dev/stdout /var/log/ngi...   22 B                
<missing>           2 days ago          /bin/sh -c set -x  && apt-get update  && a...   54.1 MB             
<missing>           2 days ago          /bin/sh -c #(nop)  ENV NJS_VERSION=1.15.12...   0 B                 
<missing>           2 days ago          /bin/sh -c #(nop)  ENV NGINX_VERSION=1.15....   0 B                 
<missing>           2 days ago          /bin/sh -c #(nop)  LABEL maintainer=NGINX ...   0 B                 
<missing>           2 days ago          /bin/sh -c #(nop)  CMD ["bash"]                 0 B                 
<missing>           2 days ago          /bin/sh -c #(nop) ADD file:fcb9328ea4c1156...   55.3 MB    



使用 docker commit 命令,手动操作给旧的镜像添加了新的一层,形成新的镜像, 多层存储机制

docker commit 对镜像的操作都是黑箱操作,生成的镜像被称为黑箱镜像   ,不推荐使用

上一篇     下一篇
docker安装和使用

docker设置镜像仓库

docker run 与 start的区别

使用Dockerfile定制镜像

GC性能度量指标

ZGC简单介绍