首先拉取一个镜像,在这里以NGINX为例
[root@DockServer opt]# docker pull nginx[root@DockServer opt]# docker p_w_picpathsREPOSITORY TAG IMAGE ID CREATED SIZEnginx latest b8efb18f159b 3 weeks ago 107MB
启动NGINX镜像,映射出端口
[root@DockServer opt]# docker run --name webserver -d -p 80:80 nginx8f62585b370ca34eb8c438adbab0f972e1990cee25000a742c6a2d8e7ee7ba38[root@DockServer opt]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES8f62585b370c 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.1Welcome to nginx! Welcome to nginx!
If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.
For online documentation and support please refer to
nginx.org. Commercial support is available at nginx.com.Thank you for using nginx.
可以看到能够访问在nginx docker里的东东了,下面我们修改下首页内容
进入nginx docker 里面进行修改
进入docker[root@DockServer opt]# docker exec -it webserver bashroot@8f62585b370c:/# echo 'Hello, Docker!
' > /usr/share/nginx/html/index.htmlroot@8f62585b370c:/# exitexit
再次访问看看
[root@DockServer opt]# curl http://127.0.0.1Hello, Docker!
可以看出,已经修改成功,我们保存成镜像
[root@DockServer opt]# docker commit --author "Ding Jin" --message "修改nginx默认网页" webserver webserver:v2sha256:ca35d11b57bac6e3e4ebab15aaff528c8530f7f5e59e00f58fa61e86edf1aa91[root@DockServer opt]# docker p_w_picpathsREPOSITORY TAG IMAGE ID CREATED SIZEwebserver v2 ca35d11b57ba 6 seconds ago 107MBnginx latest b8efb18f159b 3 weeks ago 107MB已经可以看到webserver:v2镜像了,运行下[root@DockServer opt]# docker run --name web2 -d -p 81:80 webserver:v21647edeba49aa664c0ccf642248f6b30b36c6b08990ede580a5803f1a59ae545[root@DockServer opt]# curl http://127.0.0.1:81 Hello, Docker!
可以了解以下命令,
查看webserver做了哪些更改,即和源镜像对比不同[root@DockServer opt]# docker diff webserverC /rootA /root/.bash_historyC /runA /run/nginx.pidC /varC /var/cacheC /var/cache/nginxA /var/cache/nginx/uwsgi_tempA /var/cache/nginx/client_tempA /var/cache/nginx/fastcgi_tempA /var/cache/nginx/proxy_tempA /var/cache/nginx/scgi_tempC /usrC /usr/shareC /usr/share/nginxC /usr/share/nginx/html查看webserver:v2历史文件变动记录[root@DockServer opt]# docker history webserver:v2IMAGE CREATED CREATED BY SIZE COMMENTca35d11b57ba 4 minutes ago nginx -g daemon off; 98B 修改nginx默认网页b8efb18f159b 3 weeks ago /bin/sh -c #(nop) CMD ["nginx" "-g" "daem... 0B3 weeks ago /bin/sh -c #(nop) STOPSIGNAL [SIGTERM] 0B 3 weeks ago /bin/sh -c #(nop) EXPOSE 80/tcp 0B 3 weeks ago /bin/sh -c ln -sf /dev/stdout /var/log/ngi... 0B 3 weeks ago /bin/sh -c apt-get update && apt-get inst... 52.2MB 3 weeks ago /bin/sh -c #(nop) ENV NJS_VERSION=1.13.3.... 0B 3 weeks ago /bin/sh -c #(nop) ENV NGINX_VERSION=1.13.... 0B 3 weeks ago /bin/sh -c #(nop) MAINTAINER NGINX Docker... 0B 3 weeks ago /bin/sh -c #(nop) CMD ["bash"] 0B 3 weeks ago /bin/sh -c #(nop) ADD file:fa8dd9a679f473a... 55.2MB
结合上篇,我们上传到本地私有仓库,然后就直接可以在本地调用了~~