How to enter in a Docker container already running with a new TTY

前端 未结 11 1358
你的背包
你的背包 2020-11-29 14:20

I have a container that is running the Apache service in the foreground. I would like to be able to access the container from another shell in order to \"poke around\" insid

相关标签:
11条回答
  • 2020-11-29 14:41

    What about running tmux/GNU Screen within the container? Seems the smoother way to access as many vty as you want with a simple:

    $ docker attach {container id}
    
    0 讨论(0)
  • 2020-11-29 14:48

    You should use Jérôme Petazzoni's tool called 'nsenter' to enter a container without using SSH. See: https://github.com/jpetazzo/nsenter

    Install with simply running: docker run -v /usr/local/bin:/target jpetazzo/nsenter

    Then use the command docker-enter <container-id> to enter the container.

    0 讨论(0)
  • 2020-11-29 14:49
    docker exec -ti 'CONTAINER_NAME' sh
    
    or
    
    docker exec -ti 'CONTAINER_ID' sh
    
    
    0 讨论(0)
  • 2020-11-29 14:50

    I started powershell on a running microsoft/iis run as daemon using

    docker exec -it <nameOfContainer> powershell
    
    0 讨论(0)
  • 2020-11-29 14:51

    With docker 1.3, there is a new command docker exec. This allows you to enter a running container:

    docker exec -it [container-id] bash
    
    0 讨论(0)
  • 2020-11-29 14:52

    Update

    As of docker 0.9, for the steps below to now work, one now has to update the /etc/default/docker file with the '-e lxc' to the docker daemon startup option before restarting the daemon (I did this by rebooting the host).

    update to the /etc/default/docker file

    This is all because...

    ...it [docker 0.9] contains a new "engine driver" abstraction to make possible the use of other API than LXC to start containers. It also provide a new engine driver based on a new API library (libcontainer) which is able to handle Control Groups without using LXC tools. The main issue is that if you are relying on lxc-attach to perform actions on your container, like starting a shell inside the container, which is insanely useful for developpment environment...

    source

    Please note that this will prevent the new host only networking optional feature of docker 0.11 from "working" and you will only see the loopback interface. bug report


    It turns out that the solution to a different question was also the solution to this one:

    ...you can use docker ps -notrunc to get the full lxc container ID and then use lxc-attach -n <container_id> run bash in that container as root.

    Update: You will soon need to use ps --no-trunc instead of ps -notrunc which is being deprecated.

    enter image description here Find the full container ID

    enter image description here Enter the lxc attach command.

    enter image description here Top shows my apache process running that docker started.

    0 讨论(0)
提交回复
热议问题