Skip to content

Quick Docker command cheats

Thought I’d knock up a quick cheat sheet for docker commands i use on the daily for anyone interested

Getting information

Commands used to get information about the containers and configuration .

docker ps

This command will show all running containers on the system and can be suffixed with an “-a”  to include the stopped containers.

docker stats

As you’d imagine this shows a up to date table of the currently running containers and their resource usage, Ctrl + C to exit.

docker logs <container name>

This can be used to view the logs of containers and can be suffixed with “-f” to follow the logs as they are written, Ctrl + C to exit.

Container management

docker stop <container name>

This will stop the running container

docker start <container name>

This will start the running container

docker restart <container name>

This will restart the running container

Docker Compose

Commands relating to the “docker compose” utilities, these can only be ran if you are in a folder with the appropriate compose fine such as docker-compose.yml.

docker compose up

This will attempt to pull (if the image is not already present but will not update if the image exists), Create the containers and network defined in the compose file then start them in order if dependencies are specified. After its completed you will be left with the logs from all the containers running, however Ctrl + C will exit after the containers are stopped. The containers can be ran detached id the command is suffixed with a “-d” 

docker compose pull

This will download the container images needed for the compose file but no further actions taken.

docker compose logs

Same as the “docker logs” but will show logs from every container in the compose file in one

docker compose restart

This will restart all the containers listed in the compose file

Executing commands in containers

How to execute commands inside containers 

docker exec <container name> <command>

This will execute the command inside of the container (assuming the software needed to run the command is installed in the container) and return the result to the shell

docker exec -it <container name> \bin\bash (or \bin\sh)

This will drop you in to an interactive console inside the container where you can execute commands needed and simply “exit” to disconnect from it back to the host