Docker: Enter Container

The docker exec command serves for executing commands in running Docker containers.

With this command it is also possible to enter a running Docker container and start a bash session.

In this post i am showing how to enter a Docker container and execute an interactive bash shell inside it.

Cool Tip: Copying files and folders between host and Docker-containers! Read More →

How To Enter A Docker Container

Find out a container’s name or ID with the docker ps command:

$ docker ps
CONTAINER ID  IMAGE    COMMAND  CREATED      STATUS      PORTS  NAMES
72ca2488b353  my_image          X hours ago  Up X hours         my_container

Enter a Docker container by name or ID and start a bash shell:

$ docker exec -it 72ca2488b353 bash

If the bash shell is not found, you will get the message as follows:

oci runtime error: exec failed: container_linux.go:265: starting container process caused “exec: \”bash\”: executable file not found in $PATH”

In this case you can enter a Docker container and start a simple sh shell:

$ docker exec -it 72ca2488b353 sh

To enter a Docker container we use the following options:

Option Description
-i, --interactive Keep STDIN open even if not attached
-t, --tty Allocate a pseudo-TTY
Was it useful? Share this post with the world!

2 Replies to “Docker: Enter Container”

  1. Thank you very much, simple and helpful

  2. Thank you so much!

Leave a Reply