root@af8bae53bdd3:/# pwd / root@af8bae53bdd3:/# ls bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
當利用 docker run 來建立 Container 時,Docker 在後臺執行的標準操作包括:
檢查本地是否存在指定的 Image,不存在就從 Repository Hub 下載
利用 Image 建立並啟動一個 Container
分配一個檔案系統,並在 Read-only 的 Image 層外面掛載一層可讀寫層
從宿主主機設定的網路橋界面中橋接一個虛擬埠到容器中去
從位址池中設定一個 IP 位址給 Container
執行使用者指定的應用程式
執行完畢後 Container 被終止
啟動已終止 Container
首先,先來看看目前的 Container 狀態
1 2 3 4 5 6
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES dd1c54fef918 ubuntu:14.04 "/bin/bash" 10 minutes ago Exited (0) 3 seconds ago agitated_boyd 2f902d9238f5 chestertang/sinatra:v2 "/bin/bash" 5 days ago Exited (0) About a minute ago confident_ritchie d7b639b8385a ubuntu:12.04 "/bin/bash" 7 days ago Exited (127) 7 days ago dreamy_hypatia
CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES dd1c54fef918 ubuntu:14.04 "/bin/bash" 10 minutes ago Up 3 seconds agitated_boyd 2f902d9238f5 chestertang/sinatra:v2 "/bin/bash" 5 days ago Exited (0) About a minute ago confident_ritchie d7b639b8385a ubuntu:12.04 "/bin/bash" 7 days ago Exited (127) 7 days ago dreamy_hypatia
停止 Container
跟上面就很類似了,相對的有 start 就會有 stop
1 2 3 4 5 6 7 8 9 10 11 12 13
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES dd1c54fef918 ubuntu:14.04 "/bin/bash" 10 minutes ago Up 3 seconds agitated_boyd 2f902d9238f5 chestertang/sinatra:v2 "/bin/bash" 5 days ago Exited (0) About a minute ago confident_ritchie d7b639b8385a ubuntu:12.04 "/bin/bash" 7 days ago Exited (127) 7 days ago dreamy_hypatia
docker stop dd1c54fef918
CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES dd1c54fef918 ubuntu:14.04 "/bin/bash" 10 minutes ago Exited (0) 2 seconds ago agitated_boyd 2f902d9238f5 chestertang/sinatra:v2 "/bin/bash" 5 days ago Exited (0) About a minute ago confident_ritchie d7b639b8385a ubuntu:12.04 "/bin/bash" 7 days ago Exited (127) 7 days ago dreamy_hypatia
docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES 31cec6c9afae ubuntu:14.04 "/bin/sh -c 'while t…" 11 seconds ago Up 10 seconds confident_mirzakhani