# Docker 學習日誌(3) ###### tags: `Docker` ## 常用的Docker 指令介紹 ### Example1 ```shell= $ docker run -d -p 8080:80 --restart=always --name even evenyang85/docker-test ``` 參數說明: - -d:把 container 執行在背景裡 - -p: 做 port 的mapping,container裡的port 80 mapping 到 host 的8080 port - --restart=always:如果 container 遇到例外的情況被 stop 掉,例如是重新開機,docker 會試著重新啟動此 container - --name=registry:設定 container 的 name 為 nginx - 最後一個參數 nginx 是 docker image 的 Name 使用 docker run 指令的流程如下: (1)會試著在 local 裡找有沒有 nginx Docker Image,如果沒有會自動的從 Docker Hub 上 pull 下來 (2)有了 Docker Image 之後從會mount Init設定 Container 系統和 mount 可讀可寫層 (3)Container 啟動完成 ### Example2 在執行 Container 如何看到 log,指令如下 ```shell= $ docker logs even ``` ### Example3 如何看到執行了哪些 Container,可以使用以下的指令 ```shell= $ docker ps -a ``` 參數說明: -a:如果沒有加上 -a 參數,只會顯示 running 的 containe ### Example4 如何把執行的 Container 刪除掉,使用以下的指令 ```shell= $ docker rm -f even ``` 參數說明: - -f:強制刪除 Container - even 為 Container Name ### Example5 如何把 Docker Image 刪除掉,使用以下的指令 ```shell= $ docker rmi evenyang85/docker-test ``` ## Reference [https://ithelp.ithome.com.tw/articles/10191634](https://ithelp.ithome.com.tw/articles/10191634)