Is it possible to start a shell session in a running container (without ssh)

后端 未结 15 1154
滥情空心
滥情空心 2020-11-29 14:33

I was naively expecting this command to run a bash shell in a running container :

docker run \"id of running container\" /bin/bash

it look

15条回答
  •  渐次进展
    2020-11-29 15:07

    first, get the container id of the desired container by

    docker ps
    

    you will get something like this:

    CONTAINER ID        IMAGE                  COMMAND             CREATED             STATUS                          PORTS                    NAMES
    3ac548b6b315        frontend_react-web     "npm run start"     48 seconds ago      Up 47 seconds                   0.0.0.0:3000->3000/tcp   frontend_react-web_1
    
    

    now copy this container id and run the following command:

    docker exec -it container_id sh
    
    docker exec -it 3ac548b6b315 sh
    
    

提交回复
热议问题