Jordan Savant // Software Engineer

Docker Commands

Images

List docker images

docker image ls

Build a Dockerfile folder into an image

docker image build [path to folder] -t [tag name]

Containers

List running containers

docker ps

Create a docker container from an image and run in the foreground

docker run -p [host port]:[docker port] [docker image tag]

Run in background

docker run -d -p [host port]:[docker port] [docker image tag]

Run with mounted volume

docker run -d -v [/path/to/host/folder]:[/path/to/docker/mount] -p [host port]:[docker port] [docker image tag]

Attach to the container

docker exec -t -i [container-id] /bin/bash

Remove all old containers

docker rm $(docker ps -qa --no-trunc --filter "status=exited")

Clean up old images, containers, networks and cache

docker system prune -f