docker火的一塌糊塗,做爲一名Noder更應該去了解,學習以及應用她了。本篇先去了解下,docker基本的概念和使用,高大上的設計lxc的我也沒看懂呢。redis
###1 docker的核心組件docker
###2 兩個命令 我最經常使用的兩個命令,來了解docker的狀況ubuntu
suntopo@suntopo-X550VX:~$ sudo docker images [sudo] password for suntopo: REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu latest c73a085dc378 2 weeks ago 127.1 MB redis latest 1aa84b1b434e 2 weeks ago 182.9 MB mongo latest 48b8b08dca4d 5 weeks ago 366.4 MB redis <none> 0d1cbfaa41da 5 weeks ago 185 MB hello-world latest c54a2cc56cbb 3 months ago 1.848 kB
查看本機已有的鏡像bash
suntopo@suntopo-X550VX:~$ sudo docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 97714d985a97 ubuntu "/bin/bash" 5 days ago Exited (0) 5 days ago modest_babbage 254938ab2e20 0d1cbfaa41da "docker-entrypoint.sh" 2 weeks ago Up 4 hours 127.0.0.1:6379->6379/tcp zen_murdock 0a1a11d5263b mongo "/entrypoint.sh mongo" 3 weeks ago Up 4 hours 127.0.0.1:27017->27017/tcp berserk_ride
查看本機已有的容器tcp
###3 如何建立一個容器ide
一般在建立命令的時候大部分會使用一條綜合的命令學習
suntopo@suntopo-X550VX:~$ sudo docker run -ti ubuntu root@435d6d16ed82:/#
可是我的更傾向於使用多條命令設計
下載鏡像文件3d
因爲我以前已經下載過,因此這裏會有些不一樣code
suntopo@suntopo-X550VX:~$ sudo docker pull ubuntu Using default tag: latest latest: Pulling from library/ubuntu Digest: sha256:28d4c5234db8d5a634d5e621c363d900f8f241240ee0a6a978784c978fe9c737 Status: Image is up to date for ubuntu:latest
建立容器
若是不指定容器的名稱,系統會默認分配一個,這是是furious_mccarthy
suntopo@suntopo-X550VX:~$ sudo docker create -ti ubuntu fc37b091da0b3e7992ad8bebdfe741392c552cd85dd4446fa8387bc3f212694b suntopo@suntopo-X550VX:~$ sudo docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fc37b091da0b ubuntu "/bin/bash" 48 seconds ago Created furious_mccarthy 254938ab2e20 0d1cbfaa41da "docker-entrypoint.sh" 2 weeks ago Up 4 hours 127.0.0.1:6379->6379/tcp zen_murdock 0a1a11d5263b mongo "/entrypoint.sh mongo" 3 weeks ago Up 4 hours 127.0.0.1:27017->27017/tcp berserk_ride
啓動容器
suntopo@suntopo-X550VX:~$ sudo docker start furious_mccarthy furious_mccarthy suntopo@suntopo-X550VX:~$ sudo docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fc37b091da0b ubuntu "/bin/bash" 2 minutes ago Up 2 seconds furious_mccarthy 254938ab2e20 0d1cbfaa41da "docker-entrypoint.sh" 2 weeks ago Up 4 hours 127.0.0.1:6379->6379/tcp zen_murdock 0a1a11d5263b mongo
進入容器
suntopo@suntopo-X550VX:~$ sudo docker exec -ti furious_mccarthy /bin/bash root@fc37b091da0b:/#
###4 刪除
刪除鏡像時,必需要刪除經過該鏡像建立的容器,且刪除該容器時必需要先中止容器
suntopo@suntopo-X550VX:~$ sudo docker stop furious_mccarthy furious_mccarthy suntopo@suntopo-X550VX:~$ sudo docker rm furious_mccarthy furious_mccarthy suntopo@suntopo-X550VX:~$ sudo docker rmi ubuntu Untagged: ubuntu:latest Untagged: ubuntu@sha256:28d4c5234db8d5a634d5e621c363d900f8f241240ee0a6a978784c978fe9c737 Deleted: sha256:c73a085dc3782b3fd4c032971c76d6afb45fa3728a048175c8c77d7403de5f21 Deleted: sha256:d65c79a3def77c232ad966aa21efc1abdaefe84d954de3450a29254a7bc7084b Deleted: sha256:9baff8efba34fd596f27af307d9e9c6e23b787ddef62e5357aa1fc0ae9514fbb Deleted: sha256:15d2cdb99f73294ce72eff9c1c90b2462d4239c8b48601e1731cec6e732f986c Deleted: sha256:ca01bb4a9b1c9d067a07919da3a94803e2851ccfbe68b74de0bd9937a10419f6 Deleted: sha256:040ba7b9591ca6c75584e37195149facf6906d98e3597a9b2d4c1e3889aff633