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

前端 未结 5 549
栀梦
栀梦 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

    Pull an image

    docker image pull alpine
    

    See that image is there

    docker image ls   OR  just docker images
    

    see what is inside the alpine

    docker run alpine ls -al
    

    Now your question is how to stay with the shell

    docker container run -it alpine /bin/sh
    

    You are inside shell script command line. Some distribution may have bash shell.

     docker exec -it 5f4 sh
     / # (<-- you can run linux command here!)
    

    At this point, you can use command line of alpine and do

    ls -al
    

    type exit to come out- You can run it in detached mode and it will keep running.

    With exec command we can login again

    docker container run -it -d alpine /bin/sh
    

    verify that it is UP and copy the FIRST 2 -3 digits of the container ID

    docker container ls
    

    login with exec command

    docker exec -it  sh
    

    You will need to STOP otherwise it will keep running.

    docker stop 
    

提交回复
热议问题