From e14b610325c9e8e0bc777d55c910e72697ecaa6e Mon Sep 17 00:00:00 2001 From: Max Huang Date: Sat, 30 Dec 2017 23:14:34 +0800 Subject: [PATCH] reading update --- mindmap/docker20171230.mm | 2580 +++++++++++++++++ .../README.md" | 10 + 2 files changed, 2590 insertions(+) create mode 100644 mindmap/docker20171230.mm diff --git a/mindmap/docker20171230.mm b/mindmap/docker20171230.mm new file mode 100644 index 0000000..54d63b4 --- /dev/null +++ b/mindmap/docker20171230.mm @@ -0,0 +1,2580 @@ + + + + + + + + + + +

+ https://www.docker.com/ +

+ +
+
+
+ + + + + + + + + + + + + + +

+ 可以用 iptables -L 來觀察 docker 的 port mapping +

+

+ 省略一下原本有的 Chain, Docker 會建立 DOCKER Chain 來進行 port mapping +

+

+ # iptables -L +

+

+ +

+

+ Chain OUTPUT (policy ACCEPT) +

+

+ target     prot opt source               destination         +

+

+ +

+

+ Chain DOCKER (1 references) +

+

+ target     prot opt source               destination         +

+

+ ACCEPT     tcp  --  anywhere             172.17.0.3           tcp dpt:ssh +

+

+ ACCEPT     tcp  --  anywhere             172.17.0.4           tcp dpt:commplex-main +

+

+ ACCEPT     udp  --  anywhere             172.17.0.4           udp dpt:domain +

+

+ ACCEPT     tcp  --  anywhere             172.17.0.5           tcp dpt:ssh +

+ +
+
+ + + + + + +

+ docker 會建立 proxy 來執行 port maping, 可以用 ps -ef 來觀察 +

+

+ # ps -ef | grep docker +

+

+ avahi      804     1  0  5月27 ?      00:00:12 avahi-daemon: running [dockerlab.local] +

+

+ root      1335     1  0  5月27 ?      00:34:03 /usr/bin/docker daemon -H fd:// +

+

+ root      4129  1335  0 16:28 ?        00:00:00 docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 32768 -container-ip 172.17.0.3 -container-port 22 +

+ +
+
+
+ + + + + + + + +

+ 會顯示 request / 來源IP / 目的地IP +

+

+ 但是大小有 653MB +

+ +
+
+
+
+
+ + + + + + + + + +

+ Pull an image or a repository from a registry +

+

+ Usage: docker pull [OPTIONS] NAME[:TAG|@DIGEST] +

+

+ +

+

+ Pull an image or a repository from a registry +

+

+ +

+

+   -a, --all-tags=false            Download all tagged images in the repository +

+ +
+
+ + + + + + + + + +

+ List images +

+

+ 列出 images +

+ +
+
+ + + + + + +

+ #列出 docker images +

+

+ docker  images +

+ +
+
+
+ + + + + + + +

+ Run a command in a new container +

+

+ Usage: docker  run  [OPTIONS]   IMAGE   [COMMAND]   [ARG...] +

+ +
+
+ + + + + + + + + + + + + + + +

+ 如果沒有加上 --rm +

+

+ 離開 container 之後, 用 docker  ps  -a 會發現其實還在主機上面 +

+ +
+
+
+
+ + + + + + + + + + +

+ #!/bin/bash +

+

+ for (( i=8000 ; i < 8015 ; i=i+1 )) +

+

+   do +

+

+     sudo docker run -d -p $i:22 -t sakana/sshd +

+

+   done +

+ +
+
+
+
+
+ + + + + + + +

+ flag is new and tells Docker to map any required network ports inside our container to our host. +

+

+ 自動指定Host port 來連接 +

+ +
+
+
+ + + + + + + +

+ -p, --publish=[ ]                Publish a container's port(s) to the host +

+

+ 手動指定host port 來連接 +

+ +
+
+
+ + + + + + + + + + +

+ 可以使用目錄掛載的方式, 也可以針對單一檔案來掛載, 但是都要使用絕對路徑 +

+

+ # docker   run   -v   /root/index.html:/usr/share/nginx/html/index.html   -p  8084:80   -d   nginx +

+ +
+
+
+ + + + + + + + + + + + + + + +

+ --restart  flag +

+ +
+ + + + + + +

+ 設定重新啟動 container 方式, 要檢查的話, 可能要使用 docker  inspect 來檢查 +

+

+ +

+

+ flag 有以下4種 +

+

+ +

+

+ no 不重新啟動, 為預設值 +

+

+ always   會隨著開機的時候自動啟動, 或是docker 服務重新啟動的時候啟動, 當container 退出狀況為 0 的時候會重新啟動. +

+

+ unless-stopped 不會隨著開機或是docker重新啟動,  當container 退出狀況為 0 的時候會重新啟動. +

+

+ on-failure 當container 退出狀況為不為 0 的時候會重新啟動, 最好加上次數限制 +

+ + +
+
+ + + + + + +

+ 設定開機自動啟動 +

+

+ #docker   run  --restart=always  -p 80:80  -d  nginx +

+ +
+
+
+
+
+ + + + + + + +

+ attach    Attach to a running container +

+

+ 針對已經執行的container 再次進入到容器內 +

+ +
+
+ + + + + + + + + +

+ List containers +

+

+ 列出 containers +

+ +
+
+ + + + + + +

+ 列出目前執行 container +

+

+ #docker  ps +

+

+ +

+

+ 列出所有的 container +

+

+ #docker  ps  -a +

+

+ +

+

+ 列出所有的 container, 但是只顯示 ID +

+

+ #docker  ps  -a  -q +

+

+ +

+

+ 列出所有 Container 包含 size +

+

+ #docker  ps  -s +

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + +

+ 組合技 +

+

+ 停止所有的container +

+

+ docker  stop  $( docker  ps  -aq  ) +

+ +
+
+
+ + + + + + + +

+ Return low-level information on a container or image +

+

+ Usage: docker inspect [OPTIONS] CONTAINER|IMAGE [CONTAINER|IMAGE...] +

+

+ +

+

+ 可以檢查 container 或是 image , image 部份個人喜歡看 .Config.Cmd那個部份 +

+ +
+
+ + + + + + +

+ 查詢掛載的 volume 位置 +

+

+ # docker  inspect  -f  {{.Mounts}}   CONTAINERID +

+ +
+
+ + + + + + +

+ 檢查網路 IP +

+

+ # docker   inspect   --format   '{{ .NetworkSettings.IPAddress }}'  CONATINERID +

+ +
+
+ + + + + + +

+ 查詢 image  的CMD, 以 nginx 來說 +

+

+ # docker  inspect  -f  {{.Config.Cmd}}   nginx +

+ +
+
+ + + + + + +

+ 檢查狀態 有加上 json 會顯示欄位值 -f / --format 可以指定輸出的格式 ' ' 內為內容 +

+

+ +

+

+ # docker inspect --format='{{json .State }}'  CONTAINERID +

+

+ # docker inspect --format='{{.State }}'  CONTAINERID +

+

+ +

+

+ 也可以指定細項 +

+

+ # docker inspect --format='{{json .State.Status }}' CONTAINERID +

+

+ +

+

+ 所以可以用敘述的方式輸出 +

+

+ # docker  inspect -f '{{.Name}} 的執行狀態 {{.State.Status}}'  CONTAINERID +

+ +
+
+
+ + + + + + + + +

+ 組合技 +

+

+ 移除所有的container, 但是要先停止 +

+

+ docker  rm  $( docker  ps  -aq  ) +

+ +
+
+ + + + + + + + + + + + + + + +

+ Remove one or more images +

+

+ 移除 docker images 但是要先移除所有相關 container +

+ +
+
+ + + + + + + + + +

+ Copy files/folders between a container and the local filesystem +

+

+ 在 container 與 host 複製檔案 +

+

+ +

+

+ Usage: docker cp [OPTIONS] CONTAINER:PATH LOCALPATH|- +

+

+ docker cp [OPTIONS] LOCALPATH|- CONTAINER:PATH +

+ +
+
+ + + + + + +

+ 從 host 複製 host.txt 到名稱為testcopy 容器內 +

+

+ #docker  cp  host.txt   testcopy:/root/host.txt +

+

+ +

+

+ 從名稱為 testcopy 容器/root/file.txt 複製到目前的目錄 +

+

+ # docker  cp   testcopy:/root/file.txt   . +

+ +
+
+
+ + + + + + + +

+ Run a command in a running container +

+

+ +

+

+ Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...] +

+ +
+
+
+ + + + + + + +

+ Create a new image from a container's changes +

+

+ +

+

+ Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]] +

+ +
+
+
+ + + + + + + +

+ Inspect changes on a container's filesystem +

+

+ +

+

+ Usage: docker diff [OPTIONS] CONTAINER +

+ +
+
+ + + + + + +

+ # docker   diff   b7d075f34daf +

+

+ C /var +

+

+ A /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_trusty-updates_InRelease +

+

+ D /var/cache/apt/pkgcache.bin +

+ +
+ + + + + + +

+ A - Add +

+

+ C - Change made +

+

+ D - deleted +

+ +
+
+
+
+ + + + + + + +

+ Export a container's filesystem as a tar archive +

+

+ 將 container 匯出為 tar 檔案 +

+

+ Usage: docker export [OPTIONS] CONTAINER +

+ +
+
+ + + + + + +

+ # docker   export   b7d075f34daf   >   update.tar +

+ +
+
+
+ + + + + + + +

+ Import the contents from a tarball to create a filesystem image +

+

+ +

+

+ Usage: docker  import  [OPTIONS]  file|URL|-   [REPOSITORY[:TAG]] +

+ +
+
+ + + + + + +

+ 將 update.tar 匯入為 test:update +

+

+ #docker  import  update.tar  test:update +

+

+ +

+

+ 將 update.tar 匯入為 test:update, 這邊使用 input redirection 方式, 所以要加 - +

+

+ #docker  import  -  test:update  <  update.tar +

+ +
+
+
+ + + + + + + +

+ Save an image(s) to a tar archive +

+

+ 將 image 匯出為 tar 檔案 +

+

+ Usage: docker save [OPTIONS] IMAGE [IMAGE...] +

+ +
+
+
+ + + + + + + +

+ Load an image from a tar archive or STDIN +

+

+ Usage: docker load [OPTIONS] +

+ +
+
+ + + + + + +

+ 將 update1.tar 匯入為 image, 如果不是用 input redirection 就要加上 -i +

+

+ # docker  load  -i  update1.tar +

+

+ +

+

+ 使用 input redirection 方式 +

+

+ # docker load < update1.tar +

+ +
+
+ + + + + + +

+ 跟 docker import 方式不同的是 +

+

+ docker load 會遵循之前 image 的 repo與tag +

+

+ 但是 docker import 則可以自訂 repo:tag +

+ +
+
+
+ + + + + + + +

+ Build an image from a Dockerfile +

+

+ 透過 Dockerfile 建立 image +

+

+ Usage: docker   build   [OPTIONS]    PATH | URL | - +

+ +
+
+ + + + + + + + + + + + + + +

+ Tag an image into a repository +

+

+ Usage: docker  tag  [OPTIONS]   IMAGE[:TAG]   [REGISTRYHOST/]  [USERNAME/]NAME[:TAG] +

+ +
+
+ + + + + + +

+ # docker  tag  ubuntu:14.04 foobar:cookbook +

+ +
+
+
+ + + + + + + +

+ Register or log in to a Docker registry +

+

+ Usage: docker  login  [OPTIONS]  [SERVER] +

+

+ +

+

+ Register or log in to a Docker registry. +

+

+ If no server is specified "https://index.docker.io/v1/" is the default. +

+ +
+
+ + + + + + +

+ 成功登入後相關 token 存放在 +

+

+ ~/.docker/config.json +

+ +
+
+
+ + + + + + + +

+ Search the Docker Hub for images +

+

+ Usage: docker search [OPTIONS] TERM +

+ +
+
+
+ + + + + + + +

+ Usage: docker port [OPTIONS] CONTAINER [PRIVATE_PORT[/PROTO]] +

+

+ +

+

+ List port mappings or a specific mapping for the CONTAINER +

+ +
+
+ + + + + + + + + +

+ Usage: docker swarm COMMAND +

+

+ +

+

+ Manage Docker Swarm +

+ +
+
+ + + + + + + +

+ Usage: docker swarm init [OPTIONS] +

+

+ +

+

+ Initialize a swarm +

+

+ 建立 swarm +

+ +
+
+ + + + + + + + + +

+ Usage: docker swarm join-token [-q] [--rotate] (worker|manager) +

+

+ +

+

+ Manage join tokens +

+

+ 查詢 worker 或是 manager 的 join token +

+ +
+
+ + + + + + + + + +

+ Usage: docker swarm join [OPTIONS] HOST:PORT +

+

+ +

+

+ Join a swarm as a node and/or manager +

+

+ 加入 swarm +

+ +
+
+
+ + + + + + + +

+ Usage: docker swarm leave [OPTIONS] +

+

+ +

+

+ Leave a swarm +

+

+ 將work node 離開 swarm mode +

+ +
+
+ + +
+ + + + + + + +

+ Usage: docker node COMMAND +

+

+ +

+

+ Manage Docker Swarm nodes +

+

+ +

+

+ Options: +

+

+       --help   Print usage +

+ +
+
+ + + + + + + +

+ Usage: docker node ls [OPTIONS] +

+

+ +

+

+ List nodes in the swarm +

+

+ 列出 swarm 的nodes +

+ +
+
+
+ + + + + + + +

+ Usage: docker node inspect [OPTIONS] self|NODE [NODE...] +

+

+ +

+

+ Display detailed information on one or more nodes +

+

+ 列出node 詳細資訊, 可以用 --pretty 使用易讀格式 +

+ +
+
+ + + + + + + + + +

+ Usage: docker node rm [OPTIONS] NODE [NODE...] +

+

+ +

+

+ Remove one or more nodes from the swarm +

+

+ 移除 swarm node +

+ +
+ + + + +
+ + + + + + + +

+ Usage: docker info +

+

+ +

+

+ Display system-wide information +

+ +
+
+
+ + + + + + + +

+ Usage: docker history [OPTIONS] IMAGE +

+

+ +

+

+ Show the history of an image +

+

+ 顯示 image history 可以協助追溯 Dockerfile +

+ +
+
+ + + + + + +

+ 觀察某個 image history 來了解 Dockerfile +

+

+ #docker  history  --no-trunc  IMAGEID +

+ +
+
+
+ + + + + + + +

+ Usage: docker system COMMAND +

+

+ +

+

+ Manage Docker +

+ +
+
+ + + + + + + +

+ Usage: docker system prune [OPTIONS] +

+

+ +

+

+ Remove unused data +

+

+ +

+

+ #移除停止的 container, 沒有使用的 network, dangling images and build caches +

+

+ +

+

+ #The command we’re going to be executing is docker system prune -f which will remove all stopped containers, all unused networks, all dangling images and build caches. +

+ +
+
+ + + + + + +

+ # docker   system  prune +

+ +
+
+
+
+ + + + + + + +

+ Usage: docker stats [OPTIONS] [CONTAINER...] +

+

+ +

+

+ Display a live stream of container(s) resource usage statistics +

+

+ +

+

+ #使用 Ctrl + C 退出, 預設針對全部觀察, 也可以針對某個containerID +

+ +
+
+ + + + + + +

+ 針對所有執行中的 container 顯示狀態, 加上 -a 可以顯示全部 +

+

+ # docker  stats +

+

+ +

+

+ 自訂stat 輸出格式, table 可以顯示欄位名稱, 加上 tab 可以排列整齊 +

+

+ # docker  stats  --format  "table {{.Name}}\t {{.Container}}\t {{.CPUPerc}}\t {{.MemPerc}}\t {{.NetIO}}\t {{.BlockIO}}\t {{.PIDs}} " +

+ +
+
+
+ + + + + + + +

+ Usage: docker logs [OPTIONS] CONTAINER +

+

+ +

+

+ Fetch the logs of a container +

+

+ +

+

+ #一次只能針對一個 container +

+ +
+
+ + + + + + +

+ 顯示 log, 可以加上 -f 持續顯示, 或是 -t 顯示時間, 或是 --tail 顯示最後幾筆 +

+

+ #docker   logs   CONTAINERID +

+

+ #docker   logs  -f   CONTAINERID +

+ +
+
+
+ + + + + + + +

+ Usage: docker create [OPTIONS] IMAGE [COMMAND] [ARG...] +

+

+ +

+

+ Create a new container +

+

+ +

+

+ #建立 container, 但沒有馬上啟動, 要搭配 docker  start +

+ +
+
+
+
+
+ + + + + + + +

+ 透過Dockerfile 建立 image +

+

+ 可以 #man  Dockerfile +

+ +
+
+ + + + + + + + + + + + + +

+ FROM  image@digest +

+ +
+
+
+ + + + + + + + + + +

+ 格式為 WORKDIR /path/to/workdir。 +

+

+ 為後續的 RUN , CMD , ENTRYPOINT 指令指定工作目錄。 +

+ +
+
+
+ + + + + + + +

+ 有兩種 form +

+

+ +

+

+ # the command is run in a shell - /bin/sh -c +

+

+ RUN <command> +

+

+ +

+

+ # Executable form +

+

+ RUN ["executable", "param1", "param2"] +

+ +
+
+ + + + + + +

+ Do not confuse RUN with CMD. RUN runs a command and commits the result. +

+

+ CMD executes nothing at build time, but specifies the intended command for the image. +

+ +
+
+
+ + + + + + + +

+ 有 3 種 forms +

+

+ +

+

+ # Executable form +

+

+ CMD ["executable", "param1", "param2"]` +

+

+ +

+

+ # Provide default arguments to ENTRYPOINT +

+

+ CMD ["param1", "param2"]` +

+

+ +

+

+ # the command is run in a shell - /bin/sh -c +

+

+ CMD command param1 param2 +

+ +
+
+ + + + + + + + + + +

+ The EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime. +

+

+ 設定 container 預設 listen port +

+

+ +

+

+ EXPOSE <port> [<port>...] +

+ +
+
+
+ + + + + + + +

+ The ENV instruction sets the environment variable <key> to  the value <value>. This value is passed to all future  RUN, ENTRYPOINT, and CMD instructions. +

+

+ +

+

+ 設定變數 +

+

+ +

+

+ ENV <key> <value> +

+ +
+
+
+ + + + + + + +

+ ADD has two forms: +

+

+ ADD <src> <dest> +

+

+ +

+

+ # Required for paths with whitespace +

+

+ ADD ["<src>",... "<dest>"] +

+ +
+ + + + + + + + + + + + + +

+ COPY +

+

+          -- COPY has two forms: +

+

+                 COPY <src> <dest> +

+ +
+ + +
+ + + + + + + +

+ ENTRYPOINT has two forms: +

+

+ +

+

+ # executable form +

+

+ ENTRYPOINT ["executable", "param1", "param2"]` +

+

+ +

+

+ # run command in a shell - /bin/sh -c +

+

+ ENTRYPOINT command param1 param2 +

+ +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +

+ 方式 1 上網搜尋 +

+

+ https://hub.docker.com/ +

+ +
+
+ + + + + + +

+ 方式 2 使用指令 +

+

+ 使用 docker  search 來搜尋 +

+ +
+
+
+ + + + + + + +

+ 使用  docker  pull 來下載 image +

+

+ > docker  pull  opensuse:13.2 +

+ +
+
+
+ + + + + + + +

+ 方式 1 修改現有的映像檔 +

+ +
+ + + + + + +

+  下載 training/sinatra Repository映像檔 ( 可以注意到下載了所有 TAG 的映像檔, 從 training/sinatra ) +

+

+ +

+

+  > docker   pull   training/sinatra +

+

+ +

+

+  觀察 images +

+

+ > docker images +

+

+ +

+

+ 執行之前先列出目前執行的 Container +

+

+ docker  ps 可以列出 container +

+

+ -a 是列出所有的 container +

+

+ 如果沒有加上 -a 則是列出目前有執行指令的 container +

+

+ +

+

+  > docker  ps -a +

+

+ +

+

+ 執行 docker image 到  container ( 這次不加上 --rm, 也就是說 exit 之後不刪除 ) +

+

+ +

+

+  > docker    run    -i    -t    training/sinatra  /bin/bash +

+

+ +

+

+ 輸入 exit 離開 container +

+

+ root@6764848c94c4:/# exit +

+

+ +

+

+ 再次觀察 container +

+

+ > docker  ps -a +

+

+ +

+

+ 跟上面比對就會發現, 剛剛登入 shell 的時候 root@後面那串就是 container ID +

+

+ +

+

+ 再次執行一個新的 container +

+

+ +

+

+  > docker  run  -i  -t  training/sinatra  /bin/bash +

+

+ root@ddc3cdc142f3:/# +

+

+ +

+

+  這邊就會發現 container ID 是不一樣, 因為是另外一個 +

+

+ +

+

+  我們基於這個來修改成我們的映像檔 +

+

+ 安裝 json 套件來作出差異 +

+

+ root@ddc3cdc142f3:/# gem  install json +

+

+ +

+

+ 離開 container +

+

+ +

+

+ 這樣這個映像檔就跟之前不一樣了 +

+

+ 接下來透過 docker  commit 來建立新的 +

+

+ +

+

+ +

+

+ > docker   commit   -m "Add json"  -a "sakana"   ddc3cdc142f3    testrepo/testimage:vTEST +

+

+ 220501802d62b8aca6ed82aad9ea99c2dc9a12d195638b6bdf47f20aa8e92860 +

+

+ +

+

+  commit   提交一個新的 image +

+

+ -m 訊息Commit message +

+

+ -a  作者 Author (e.g., "John Hannibal Smith <hannibal@a-team.com>") +

+

+ ddc3cdc142f3 是container ID +

+

+ testrepo/testimage:vTEST 是 Repository名稱/映像檔名稱:TAG +

+

+ +

+

+  觀察 images +

+

+ > docker   images +

+

+ +

+

+ 這個時候就會知道, 如果我們日後不上傳到 Docker Hub, 其實 Repository名稱是可以自己取的, 沒有影響, 但是如果要上傳, 就是要註冊 Docker Hub的帳號, 符合上面的規則才可以. +

+ +
+
+
+ + + + + + + +

+ 我們可以透過 docker  build 配合 Dockerfile 來建立映像檔 +

+

+ +

+

+ +

+

+ 首先觀察目前的路徑 +

+

+ > pwd +

+

+ /home/max +

+

+ +

+

+  建立目錄 +

+

+ > mkdir  sakana +

+

+ +

+

+  進入該目錄 +

+

+ > cd   sakana/ +

+

+ +

+

+  建立 Dockerfile +

+

+ > vi   Dockerfile +

+

+ # 用於註解 +

+

+ # 後續的流程, 前面都要大寫 +

+

+ # FROM 基於那個 image +

+

+ FROM ubuntu:14.04 +

+

+ # MAINTAINER 維護作者 +

+

+ MAINTAINER Max Huang < sakana@study-area.org > +

+

+ # RUN 要執行的指令 +

+

+ RUN apt-get update && apt-get install -y ruby ruby-dev +

+

+ RUN gem install sinatra +

+

+ +

+

+  > docker    build    -t    sakanatest/testimage    /home/max/sakana +

+

+ +

+

+ > docker  images +

+ +
+
+
+
+ + + + + + + +

+ 可以透過  docker tag 來設定 映像檔的 TAG +

+

+ +

+

+  > docker  images +

+

+ REPOSITORY             TAG                 IMAGE ID            CREATED             VIRTUAL SIZE +

+

+ sakanatest/testimage   latest              dd38d73f4e20        2 minutes ago       318.7 MB +

+

+ testrepo/testimage     vTEST               220501802d62        37 minutes ago      452.1 MB +

+

+ ubuntu                 14.04               91e54dfb1179        13 days ago         188.3 MB +

+

+ ubuntu                 12.04               57bca5139a13        13 days ago         134.8 MB +

+

+ opensuse               13.2                d6b241b32a2d        5 weeks ago         93.99 MB +

+

+ opensuse               latest              d6b241b32a2d        5 weeks ago         93.99 MB +

+

+ training/sinatra       latest              f0f4ab557f95        15 months ago       447 MB +

+

+ +

+

+  > docker    tag    dd38d73f4e20    sakanatest/testimage:tagTest +

+ +
+
+
+ + + + + + + +

+ 先觀察 container +

+

+ > docker    ps     -a +

+

+ CONTAINER ID        IMAGE                      COMMAND             CREATED             STATUS                         PORTS               NAMES +

+

+ acfed6e70946        testrepo/testimage:vTEST   "/bin/bash"         About an hour ago   Exited (0) About an hour ago                       furious_pare        +

+

+ ddc3cdc142f3        training/sinatra           "/bin/bash"         About an hour ago   Exited (0) About an hour ago                       serene_tesla        +

+

+ 6764848c94c4        training/sinatra           "/bin/bash"         About an hour ago   Exited (0) About an hour ago                       elegant_lalande    +

+

+ +

+

+  觀察映像檔 +

+

+ 這邊可以觀察到 sakanatest/testimage 沒有container使用中 +

+

+ testrepo/testimage 以及 trainging/sinatra 有 container 使用中 +

+

+ +

+

+  > docker    images +

+

+ REPOSITORY             TAG                 IMAGE ID            CREATED             VIRTUAL SIZE +

+

+ sakanatest/testimage   latest              dd38d73f4e20        About an hour ago   318.7 MB +

+

+ sakanatest/testimage   tagTest             dd38d73f4e20        About an hour ago   318.7 MB +

+

+ testrepo/testimage     vTEST               220501802d62        About an hour ago   452.1 MB +

+

+ ubuntu                 14.04               91e54dfb1179        13 days ago         188.3 MB +

+

+ ubuntu                 12.04               57bca5139a13        13 days ago         134.8 MB +

+

+ opensuse               13.2                d6b241b32a2d        5 weeks ago         93.99 MB +

+

+ opensuse               latest              d6b241b32a2d        5 weeks ago         93.99 MB +

+

+ training/sinatra       latest              f0f4ab557f95        15 months ago       447 MB +

+

+ +

+

+ +

+

+ 我們可以使用 docker  rmi 來移除 沒有 container 使用中的 image +

+

+ +

+

+ 首先針對沒有 container 運作的  sakanatest/testimage 來刪除 +

+

+ > docker   rmi   sakanatest/testimage:tagTest +

+

+ Untagged: sakanatest/testimage:tagTest +

+

+ Deleted: dd38d73f4e2021c81c52530e99eb1cb98f87b9031d50c6342e7d47b8302f78a7 +

+

+ Deleted: b987f587ddb48e0006250cc77835530f605c32647d5cbe0432ea8a5fd3769017 +

+

+ Deleted: adbe1f76147105dc554a86f026dab8fa8b2019892bfb5d10cfe9e3df5bafa9b9 +

+

+ +

+

+  刪除不會有問題, 使用  docker  rmi 刪除所有 sakanatest/testimage 上面 image +

+ +
+
+
+ + + + + + +

+ 映像檔存放路徑 +

+ +
+ + +
+ + + + + + + + +

+ 觀察一次 +

+

+ > docker  ps  -a +

+

+ CONTAINER ID        IMAGE                      COMMAND             CREATED             STATUS                         PORTS               NAMES +

+

+ acfed6e70946        testrepo/testimage:vTEST   "/bin/bash"         About an hour ago   Exited (0) About an hour ago                       furious_pare        +

+

+ ddc3cdc142f3        training/sinatra           "/bin/bash"         About an hour ago   Exited (0) About an hour ago                       serene_tesla        +

+

+ 6764848c94c4        training/sinatra           "/bin/bash"         2 hours ago         Exited (0) 2 hours ago                             elegant_lalande +

+

+ +

+

+  移除 container 可以使用  docker  rm 指令來完成 +

+

+ +

+

+  > docker    rm    acfed6e70946 +

+

+ acfed6e70946 +

+

+ +

+

+  確認已經刪除 +

+

+ > docker  ps  -a +

+

+ CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                   PORTS               NAMES +

+

+ ddc3cdc142f3        training/sinatra    "/bin/bash"         2 hours ago         Exited (0) 2 hours ago                       serene_tesla        +

+

+ 6764848c94c4        training/sinatra    "/bin/bash"         2 hours ago         Exited (0) 2 hours ago                       elegant_lalande  +

+ +
+
+ + + + + + + +

+ docker  ps 指令加上 -q 只會列出 container ID +

+

+ > docker  ps  -a  -q +

+

+ ddc3cdc142f3 +

+

+ 6764848c94c4 +

+

+ +

+

+  但是做這件事的時候要三思而後行 +

+

+ > docker  rm  $( docker  ps  -a  -q ) +

+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + +

+ Private Registry +

+

+ 私有倉庫 +

+ +
+ + + + + + +

+ 可以參考 +

+

+ https://philipzheng.gitbooks.io/docker_practice/content/repository/local_repo.html +

+ +
+ + + + + + + + + +

+ #docker  pull  registry:2 +

+

+ +

+

+ # docker   run   -d   -p  5000:5000   registry:2 +

+ +
+
+ + + + + + + + + + + + + + + +

+ 查詢私有倉庫 repo +

+

+ # curl -i http://localhost:5000/v2/_catalog +

+ +
+
+ + + + + + +

+ 查詢某個 repo 相關資訊, busy1 為 reponame, test2 為tag +

+

+ # curl -i http://localhost:5000/v2/busy1/manifests/test2 +

+ +
+
+ + + + + + +

+ 列出某個 repo 的 tag +

+

+ # curl -i http://localhost:5000/v2/busy1/tags/list +

+ +
+
+
+
+
+ + + + + + + + + + + + + + + + +
diff --git "a/other_materials/Max_Huang/\346\235\276\345\264\227_Docker\351\200\231\346\250\243\345\255\270\346\211\215\346\234\211\350\266\243/README.md" "b/other_materials/Max_Huang/\346\235\276\345\264\227_Docker\351\200\231\346\250\243\345\255\270\346\211\215\346\234\211\350\266\243/README.md" index 3a5f4b5..7b39fcf 100644 --- "a/other_materials/Max_Huang/\346\235\276\345\264\227_Docker\351\200\231\346\250\243\345\255\270\346\211\215\346\234\211\350\266\243/README.md" +++ "b/other_materials/Max_Huang/\346\235\276\345\264\227_Docker\351\200\231\346\250\243\345\255\270\346\211\215\346\234\211\350\266\243/README.md" @@ -3,6 +3,16 @@ This is notes for Max reading ---------------------------------------------- +---------------------------------------------- + +2017/12/30 + +進度: Chapter 2-10 ~ Chapter 3-7 + +* docker stats +* docker logs +* docker run --name / docker run -e / docker run -v / docker run --restart + ---------------------------------------------- 2017/12/29