Start a shell in a container

If the container is running bash with PID 1

docker ps
docker attach container_id

Exiting the shell will terminate the container. To exit the container without terminating it, use Control+P+Q.

Otherwise, get the container ID

docker inspect container_id | grep Pid

Use nsenter

nsenter -m -u -n -p -i -t Pid  /bin/bash

In this case, exiting the shell will not terminate the container.

The other, (preferred way, they say) is to use docker exec to run a process in a container.

docker exec -it container_id /bin/bash
man docker-exec

In this method too, exiting the shell will not terminate the container.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s