Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

docker

tty

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" inside it and examine the files. At the moment, if I attach to the container, I am left looking at the Apache daemon and cannot run any commands.

Is it possible to attach another tty to a running container? Possibly, I can take advantage of the fact that Docker is actually just wrapping around LXC containers? I have tried sudo lxc-console -n [container-id] -t [1-4] but it appears that only one tty is made available and that is the one running the apache daemon. Perhaps there is a way to enable multiple lxc consoles during the build?

I would rather not configure and build the container with an openssh service if possible.

like image 489
Programster Avatar asked Jan 05 '14 10:01

Programster


People also ask

Can you ssh into a running docker container?

The SSH method works fine for Docker containers, too. That said, you can SSH into a Docker container using Docker's built-in docker exec . If you do not need an interactive shell, you can also use the docker attach command to connect the host's stdin and stdout to the running container and execute remote commands.

Can you interact with an application inside a container?

The answer is yes!! But using normal docker run commands, you won't be able to see or interact with the these applications. You need to connect the display with the container in order to do so.


1 Answers

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 

Note: this assumes bash is installed on your container. You may run sh or whatever interactive shell is installed on the container.

like image 71
Michael_Scharf Avatar answered Sep 18 '22 08:09

Michael_Scharf