DEV Community

James Murdza
James Murdza

Posted on

The only Docker cheatsheet you need 🐳

My reference of the most useful commands to know when you're building in Docker:

Build and run

Build an image:

docker build -t myimage .
Enter fullscreen mode Exit fullscreen mode

Build an image, deleting the old one:

docker rmi myimage && docker build -t myimage .
Enter fullscreen mode Exit fullscreen mode

Build an image, and print all the steps:

docker build --progress=plain -t myimage .
Enter fullscreen mode Exit fullscreen mode

Run container from image, with port forwarding:

docker run -p 80:80 myimage
Enter fullscreen mode Exit fullscreen mode

Run container for debugging purposes, replacing the entrypoint with a shell:

docker run --rm -it --entrypoint bash myimage
Enter fullscreen mode Exit fullscreen mode

Inventory

List all images:

docker image ls
Enter fullscreen mode Exit fullscreen mode

List all containers: (The -a flag is to show stopped containers as well)

docker container ls -a
Enter fullscreen mode Exit fullscreen mode

List all docker images and containers and file sizes:

docker system df -v
Enter fullscreen mode Exit fullscreen mode

Show the history of an image:

docker history myimage
Enter fullscreen mode Exit fullscreen mode

Clean up

**Dangling images* are untagged and not needed by any tagged images.*
**Unused image* are not needed by any existing containers.*

Delete stopped containers:

docker container prune
Enter fullscreen mode Exit fullscreen mode

Remove dangling images:

docker image prune
Enter fullscreen mode Exit fullscreen mode

Remove unused images:

docker image prune -a
Enter fullscreen mode Exit fullscreen mode

Remove build cache:

docker builder prune
Enter fullscreen mode Exit fullscreen mode

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay