DevOps Blog

Docker Commands: A Cheat Sheet

Maintanence worker working with cargo containers
Jonathan Johnson
3 minute read
Jonathan Johnson
image_pdfimage_print

Docker’s purpose is to build and manage compute images and to launch them in a container. So, the most useful commands do and expose this information.

docker
Here’s a cheat sheet on the top Docker commands to know and use.

Images and containers

The docker command line interface follows this pattern:
docker <COMMAND>

docker images
docker container

The docker images and container commands grant access to the images and containers. From here, you are permitted to do something with them, hence:

docker images <COMMAND>
Docker container <COMMAND>

There are:

  • is lists the resources.
  • cp copies files/folders between the container and the local file system.
  • create creates new container.
  • diff inspects changes to files or directories in a running container.
  • logs fetches the logs of a container.
  • pause pauses all processes within one or more containers.
  • rename renames a container.
  • run runs a new command in a container.
  • start starts one or more stopped containers.
  • stop stops one or more running containers.
  • stats displays a livestream of containers resource usage statistics.
  • top displays the running processes of a container.

View resources with ls

docker images ls
docker container ls

From the container ls command, the container id can be accessed (first column).

docker-container

Control timing with start, stop, restart, prune

  • start starts one or more stopped containers.
  • stop stops one or more running containers.
  • restart restarts one or more containers.
  • prune (the best one!) removes all stopped containers.
docker container stop <container id>
docker container start <container id>
docker container restart <container id>
docker container prune <container id>

Name a container

docker run -d -name myfirstcontainer

View vital information: Inspect, stats, top

docker container inspect <container id>

docker container top <container id>

docker container stats <container id>

  • stats displays a live stream of container(s) resource usage statistics

stats docker

  • top displays the running processes of a container:

top-docker

  • inspect displays detailed information on one or more containers. With inspect, a JSON is returned detailing the name and states and more of a container.

inspects-docker

Additional resources

For more on this topic, there’s always the Docker documentation, the BMC DevOps Blog, and these articles:

Free Download: Enterprise DevOps Skills Report

Human skills like collaboration and creativity are just as vital for DevOps success as technical expertise. This DevOps Institute report explores current upskilling trends, best practices, and business impact as organizations around the world make upskilling a top priority.


These postings are my own and do not necessarily represent BMC's position, strategies, or opinion.

See an error or have a suggestion? Please let us know by emailing blogs@bmc.com.

Run and Reinvent Your Business with BMC

From core to cloud to edge, BMC delivers the software and services that enable nearly 10,000 global customers, including 84% of the Forbes Global 100, to thrive in their ongoing evolution to an Autonomous Digital Enterprise.
Learn more about BMC ›

About the author

Jonathan Johnson

Jonathan Johnson

Jonathan Johnson is a tech writer who integrates life and technology. Supports increasing people's degrees of freedom. Visit his website at jonnyjohnson.com.