參考鏈接:https://stackoverflow.com/questions/29599632/docker-container-is-not-running/49204476
1、
Container 79b3fa70b51d seems to only do an echo. That means it starts, echo and then exits immediately. The next docker exec command wouldn't find it running in order to attach itself to that container and execute any command: it is too late. The container has already exited. The docker exec command runs a new command in a running container. The command started using docker exec will only run while the container's primary process (PID 1) is running
2、
docker run -d -v /app:/var/www/swoft --name swoft swoft/swoft // 開發環境和容器進行關聯 docker run -d --entrypoint="" -v /app:/var/www/swoft --name swoft swoft/swoft bash // 開發環境和容器進行關聯
docker ps -a
docker exec -it swoft bash
3、參考鏈接:https://segmentfault.com/a/1190000010940432
1.容器的生命周期。要把docer容器看做是一個單獨的進程及運行環境。容器不等價於一個虛擬的操作系統。Docker的開發人員也一直主張doder容器應該只運行一個進程。例如,一個web server服務就是一個進程。docker run命令就是為了運行一個進程。當一個進程結束了,那么docker容器也就結束了。
2.根據問題中描述的現象,兩條命令的差別就在與末尾是否添加了/bin/bash
這條command。暫且先停住。我們回過頭來看docker image是怎么生成的。
3.Dockerfile文件。Dockerfile文件中有兩個關鍵字CMD
和ENTRYPOINT
。其中CMD
的值是可以被覆蓋的。舉個栗子:
假設Dockerfile中的內容包含了:
FROM python CMD ["/home/hello.sh","Hello World"] ENTRYPOINT ["/home/hello.sh","xiaoming"]
那么根據CMD可被覆蓋的特征來看,如果在docker run
后增加了/bin/bash
。那么,在鏡像run的時候,執行的CMD就變成了/bin/bash
。一般鏡像文件中兩種關鍵字選用其中之一就可以了。但也可以同時使用。同時使用的時候,CMD中的值會被當作ENTRYPOINT的參數。所以,ENTRYPOINT的內容就變成["/home/hello.sh","/bin/bash"]
。
4.我們再來看我要啟動的registry鏡像中都包含了哪些CMD和ENTRYPOINT。如下圖:
根據上圖中的前兩行可知,容器運行后默認執行的是/entrypoint.sh
腳本,腳本命令的參數是/etc/docker/regis...
。所以,如果我們自己在run的時候添加了新的command,那么鏡像內置的執行命令就無法正確執行了,於是容器就Exited了。