Skip to content

How to execute commands inside a docker container?

Published:

Dockers containers are a great way to reduce the dependencies of a project as it executes. However, especially if you are not familiar with Docker, debugging and analyzing an application or other problems inside the Docker container can be challenging.

To start a bash in a Docker container there is a simple command:

docker exec -it bash

This starts a bash inside the docker container and allows you to operate in the Docker container just like on Linux.

Especially if you are debugging, you should be aware that Docker containers, depending on their structure, will terminate when the entrypoint script has finished or crashed. To prevent this you can start the Docker container with docker run -t. With this option the container will only terminate when you actually want it to and any error states can still be traced.