How to retain docker alpine container after “exit” is used?

前端 未结 5 554
栀梦
栀梦 2020-12-30 05:04

Like for example if I use command docker run -it alpine /bin/sh it starts a terminal after which I can install packages and all. Now when I use exit

5条回答
  •  伪装坚强ぢ
    2020-12-30 05:42

    The container lives as long as the specified run command process is still running. When you specify to run /bin/sh, once you exit, the sh process will die and so will you container.

    If you want to keep your container running, you have to keep the process inside running. For your case (I am not sure what you want to acheive, I assume you are just testing), the following will keep it running

    docker run -d --name alpine alpine tail -f /dev/null
    

    Then you can sh into the container using

    docker exec -it alpine sh  
    

提交回复
热议问题