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

后端 未结 15 1021
滥情空心
滥情空心 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:06

    There are two ways.

    With attach

    $ sudo docker attach 665b4a1e17b6 #by ID
    

    With exec

    $ sudo docker exec - -t 665b4a1e17b6 #by ID
    
    0 讨论(0)
  • 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
    
    
    0 讨论(0)
  • 2020-11-29 15:08

    Just do

    docker attach container_name
    

    As mentioned in the comments, to detach from the container without stopping it, type Ctrlpthen Ctrlq.

    0 讨论(0)
  • 2020-11-29 15:10

    If the goal is to check on the application's logs, this post shows starting up tomcat and tailing the log as part of CMD. The tomcat log is available on the host using 'docker logs containerid'.

    http://blog.trifork.com/2013/08/15/using-docker-to-efficiently-create-multiple-tomcat-instances/

    0 讨论(0)
  • 2020-11-29 15:12

    No. This is not possible. Use something like supervisord to get an ssh server if that's needed. Although, I definitely question the need.

    0 讨论(0)
  • 2020-11-29 15:21

    You can use

    docker exec -it <container_name> bash
    
    0 讨论(0)
提交回复
热议问题