首先拉取一个镜像,在这里以NGINX为例

[root@DockServer opt]# docker pull nginx
[root@DockServer opt]# docker p_w_picpaths
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              b8efb18f159b        3 weeks ago         107MB

启动NGINX镜像,映射出端口

[root@DockServer opt]# docker run --name webserver -d -p 80:80 nginx
8f62585b370ca34eb8c438adbab0f972e1990cee25000a742c6a2d8e7ee7ba38
[root@DockServer opt]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
8f62585b370c        nginx               "nginx -g 'daemon ..."   6 seconds ago       Up 6 seconds        0.0.0.0:80->80/tcp       webserver

访问端口,直接用命令行访问,

[root@DockServer opt]# curl http://127.0.0.1
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

可以看到能够访问在nginx docker里的东东了,下面我们修改下首页内容

进入nginx docker 里面进行修改

进入docker
[root@DockServer opt]# docker exec -it webserver bash
root@8f62585b370c:/# echo '<h1>Hello, Docker!</h1>' > /usr/share/nginx/html/index.html
root@8f62585b370c:/#  exit
exit

再次访问看看

[root@DockServer opt]# curl http://127.0.0.1
<h1>Hello, Docker!</h1>

可以看出,已经修改成功,我们保存成镜像

[root@DockServer opt]# docker commit  --author "Ding Jin <dingjin@gmail.com>"  --message "修改nginx默认网页"  webserver webserver:v2
sha256:ca35d11b57bac6e3e4ebab15aaff528c8530f7f5e59e00f58fa61e86edf1aa91
[root@DockServer opt]# docker p_w_picpaths
REPOSITORY             TAG                 IMAGE ID            CREATED             SIZE
webserver              v2                  ca35d11b57ba        6 seconds ago       107MB
nginx                  latest              b8efb18f159b        3 weeks ago         107MB

已经可以看到webserver:v2镜像了,运行下
[root@DockServer opt]# docker run --name web2 -d -p 81:80 webserver:v2
1647edeba49aa664c0ccf642248f6b30b36c6b08990ede580a5803f1a59ae545
[root@DockServer opt]# curl http://127.0.0.1:81
<h1>Hello, Docker!</h1>

可以了解以下命令,

查看webserver做了哪些更改,即和源镜像对比不同

[root@DockServer opt]# docker diff webserver
C /root
A /root/.bash_history
C /run
A /run/nginx.pid
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
C /usr
C /usr/share
C /usr/share/nginx
C /usr/share/nginx/html

查看webserver:v2历史文件变动记录

[root@DockServer opt]# docker history webserver:v2
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
ca35d11b57ba        4 minutes ago       nginx -g daemon off;                            98B                 修改nginx默认网页
b8efb18f159b        3 weeks ago         /bin/sh -c #(nop)  CMD ["nginx" "-g" "daem...   0B                  
<missing>           3 weeks ago         /bin/sh -c #(nop)  STOPSIGNAL [SIGTERM]         0B                  
<missing>           3 weeks ago         /bin/sh -c #(nop)  EXPOSE 80/tcp                0B                  
<missing>           3 weeks ago         /bin/sh -c ln -sf /dev/stdout /var/log/ngi...   0B                  
<missing>           3 weeks ago         /bin/sh -c apt-get update  && apt-get inst...   52.2MB              
<missing>           3 weeks ago         /bin/sh -c #(nop)  ENV NJS_VERSION=1.13.3....   0B                  
<missing>           3 weeks ago         /bin/sh -c #(nop)  ENV NGINX_VERSION=1.13....   0B                  
<missing>           3 weeks ago         /bin/sh -c #(nop)  MAINTAINER NGINX Docker...   0B                  
<missing>           3 weeks ago         /bin/sh -c #(nop)  CMD ["bash"]                 0B                  
<missing>           3 weeks ago         /bin/sh -c #(nop) ADD file:fa8dd9a679f473a...   55.2MB

结合上篇,我们上传到本地私有仓库,然后就直接可以在本地调用了~~