1. 建立 container
# docker create --name nginx_base -p 80:80 nginx:alpine
Unable to find image 'nginx:alpine' locally
alpine: Pulling from library/nginx
63b65145d645: Pull complete
8c7e1fd96380: Pull complete
86c5246c96db: Pull complete
b874033c43fb: Pull complete
dbe1551bd73f: Pull complete
0d4f6b3f3de6: Pull complete
2a41f256c40f: Pull complete
Digest: sha256:6318314189b40e73145a48060bff4783a116c34cc7241532d0d94198fb2c9629
Status: Downloaded newer image for nginx:alpine
3763eb9740e98479000e6daba1e62240ada2251915454f377227f6c4c74ebcd2
2. 檢查 images
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx alpine 2bc7edbc3cf2 5 weeks ago 40.7MB
3. 檢查 container
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3763eb9740e9 nginx:alpine "/docker-entrypoint.…" About a minute ago Created nginx_base
4. 啟動 container
# docker start nginx_base
nginx_base
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATU S PORTS NAMES
3763eb9740e9 nginx:alpine "/docker-entrypoint.…" 4 minutes ago Up 4 seconds 0.0.0.0:80->80/tcp nginx_base
開啟瀏覽器,輸入 http://docker-ip,應該可以看到nginx 的歡迎頁
5. 調整正在執行中的 container
以下是其中一個方式,你可以選擇你習慣的做法
# echo "helloworld" > index.html
# docker cp index.html nginx_base:/usr/share/nginx/html/index.html
重新整理頁面後,即可看到新的首頁
6. 建立新的 images
# docker commit nginx_base
sha256:d1b0833ff6de7ae692b25c79e3b7981218d76afb6e6fdf5bdff3394c345ab0ac
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> d1b0833ff6de 20 seconds ago 40.7MB
nginx alpine 2bc7edbc3cf2 5 weeks ago 40.7MB
此時新的 images 沒有 name 及 tag
7. 建立 tag
# docker tag d1b0833ff6de hello_world_nginx
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello_world_nginx latest d1b0833ff6de 2 minutes ago 40.7MB
nginx alpine 2bc7edbc3cf2 5 weeks ago 40.7MB
8. 你也可以直接透過從container 建立 images
# docker commit nginx_base hello_world_nginx2
sha256:76dc18cde292089b5bdea69a187681fafc260a8fbe77353395472154794e911e
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello_world_nginx2 latest 76dc18cde292 11 seconds ago 40.7MB
nginx alpine 2bc7edbc3cf2 5 weeks ago 40.7MB
9. 停用原始的 container
# docker stop nginx_base
nginx_base
# docker run --name hello_world -d -p 80:80 hello_world_nginx
ef65bfe96bc20ea397e60905659d1b21efe413afce69cacbe38ad8485f67a89c
10.打開瀏覽器測試畫面是否是客製化過的頁面
留言列表