30 Essential Docker Commands every developer should know

Image for post
Image for post

Here is a list of useful docker commands. I started writing this down as I was learning about docker for my own reference and also to help me remember them by organizing them into groups of commands.

I am using docker version 19.03.13.

I hope you also find it useful either as a quick refresher or as a learning tool.

  • docker version shows the Docker version information.
  • docker info displays system-wide information.
  • docker login logs in to a Docker registry
  • docker image ls lists images
  • docker image pull pulls an image from a registry
  • docker image push pushes an image into a registry
  • docker image history shows the history of an image
  • docker image inspect displays detailed information on one or more images
  • docker image tag creates a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  • docker image build builds an image from a Dockerfile
  • docker image rm removes one or more images
  • docker container ls lists containers
  • docker container run runs a command in a new container

The new container in this example below, will publish its port 80 on the host machine’s port 80 and create a container based on nginx image

docker container run — publish 80:80 — detach — name webhost nginx

The container run command below inserts an environment variable to the mysql container

docker container run -d — name mysql -e MYSQL_RANDOM_ROOT_PASSWORD=true mysql

The container run command below gets access to the bash shell of the container.

docker container run -it — name proxy nginx bash

  • docker container logs fetches the logs of a container
  • docker container top displays the running processes of a container
  • docker container rm removes one or more containers
  • docker container stop stops one or more running containers
  • docker container start starts one or more stopped containers
  • docker container inspect displays detailed information on one or more containers
  • docker container stats displays a live stream of container(s) resource usage statistics
  • docker container exec runs a command in a running container
  • docker container port lists port mappings or a specific mapping for the container
  • docker network ls lists networks
  • docker network inspect displays detailed information on one or more networks
  • docker network create creates a network
  • docker network connect connects a container to a network
  • docker network disconnect disconnects a container from a network
  • docker volume ls lists volumes
  • docker volume inspect displays detailed information on one or more volumes
  • docker volume create creates a volume

Software Architect, Coder, Tech Enthusiast.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store