Docker CLI Cheat-Sheet (Misc)

Docker is everywhere.... It's syntax is fairly simple, but sometimes you need a small prompt, this page is that prompt

Details

  • Language: Misc

Snippet

# Run an image
docker run influxdb:2.0

# Run an image and pass an environment var
docker run -e MY_VAR=foo influxdb:2.0

# Run an image and mount a volume
docker run -v influx:/var/lib/influxdb2 influxdb:2.0

# Run an image and map a port to a port on the container
docker run -p 8086:8086 -v influx:/var/lib/influxdb2 influxdb:2.0

# List running processes
docker ps

# List running containers
docker list

# List all containers
docker container list -a

# Shell into a container
docker ps # get it's container ID
docker exec -t -i $container_id bash

# Kill a running container
docker kill $container_id

# Remove a container
docker container rm $container_id

# Remove all stopped containers (use with extreme caution)
docker container prune

# List volumes
docker volume list

# Remove volume
docker volume rm $volume_name

# Remove all unused volumes 
docker volume prune