docker學習筆記(三)——建立自定義鏡像

首先拉取一個鏡像,在這裏以NGINX爲例
html

[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鏡像,映射出端口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

訪問端口,直接用命令行訪問,
web

[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裏的東東了,下面咱們修改下首頁內容docker

進入nginx docker 裏面進行修改bash

進入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

再次訪問看看curl

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

能夠看出,已經修改爲功,咱們保存成鏡像tcp

[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>

能夠了解如下命令,ide

查看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

結合上篇,咱們上傳到本地私有倉庫,而後就直接能夠在本地調用了~~
ui

相關文章
相關標籤/搜索