How to run commands inside a docker container

Sometimes things don’t go as planned and we need to debug. If you need to get a command line inside a docker container, just follow these simple steps bellow.

Quick commands

  1. Get a list of your running docker containers:
$ docker container ls
  1. Access your container by its container id with:
$ docker container exec -it <container id> bash
  1. Run all the commands you need.

Additional tips

Keep in mind that containers often come with a minimal Linux instalation (Alpine) and may not include your required utilities.

You can normally install them with apt:

docker@container$ apt install <package-name>

Once you have finished, you can close your session with:

docker@container$ exit