Back to blog
Jul 21, 2019
2 min read

Docker commands cheatsheet

One stop for all common commands

Docker container engine logo

Common terminal commands

docker ps Show running containers

docker ps -a Show all containers

docker images Show docker images in the machine

docker rm <container_name> Remove(delete) container

docker rmi <image_name> Remove(delete) image

docker stop <container_name> Stop container (without removing it)

docker start <container_name> Start the <container_name>

docker build -t my-app Build a docker image in local environment named my-app

docker run -p 4000:80 -d my-app Run container my-app. When I make a request to port 4000 (this can be an api call or a get request from a browser), I will reach to port 80 in docker environment.

-d means run this container in detached mode. Meaning don’t stop the container when I close my terminal window

docker logs <container_id> Show terminal output in running container

docker kill $(docker ps -aq) Kill all running containers

docker rm $(docker ps -aq) Remove all containers

docker exec -ti <container_name> /bin/bash Open a bash terminal in the <container_name>

docker exec -ti sh Open a shell terminal in the <container_name>

Docker compose

Docker Compose is a tool for defining and running multi-container applications.

docker compose up -d Run docker compose file and leave the container in detached mode

docker compose —verbose up Start a container with verbose settings. This is useful for debugging.