Skip to content

Instantly share code, notes, and snippets.

@sameh-sharaf
Last active December 18, 2019 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sameh-sharaf/23ea65f9bce3595a170ef1af615f9d64 to your computer and use it in GitHub Desktop.
Save sameh-sharaf/23ea65f9bce3595a170ef1af615f9d64 to your computer and use it in GitHub Desktop.
Your Humble Docker Guide

Your Humble Docker Guide

This guide gathers the basic commands every Docker user will frequently need. Personally, I keep getting back to it from time to time when my Docker knowledge gets rusty. Hope it helps you too!

List downloaded or created images

docker images

Delete image

docker rmi <image-name>

List running containers

docker ps

List all containers (including stopped ones)

docker ps -a

List container IDs

docker ps -a -q

Delete all containers

docker rm $(docker ps -a -q)

Prune unused images & containers

docker system prune

Prune all images & containers:

docker system prune -a

Build image

Note the dot (.) at the end

docker build -t image-name .

Build image referring to Dockerfile location

docker build -t image-name -f /path/to/your/Dockerfile .

Run container

Note: Run = create + start

docker run -dit image-name:latest

Create container

docker create image-name:latest

Start (existing) container

docker start <container-id>

Log into container's shell

Note: Assuming image's OS is Ubuntu/Debian

docker exec -it <container-id> sh

Stop container

docker stop <container-id>

Delete container

docker rm <container-id>

Force delete (running) container

docker rm -f <container-id>

Run container with port published

docker run -p <local-port>:<container-port> image-name:latest

E.g.: If the image exposes port 8008 and you want to use port 3000 on the machine hosting the container:

docker run -p 3000:8008 image-name:latest

Get container logs

docker logs <container-id>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment