Docker CLI Cheatsheet

less than 1 minute read

Build an image

docker build -t myImage </path/to/dockerfile>

Finding a container’s name

docker ps

Shutting down a container

docker stop <name>
docker rm <name>

Or:

docker rm -f <name>

Volumes

Creating a volume

docker volume create myVolume
docker volume inspect myVolume

Running an image connected to the volume

docker run -dp 3000:3000 -v myVolume:</path/on/container> <image-name>

Bind mounts

Running an image with a mount on the host machine

docker run -dp 3000:3000 -v </path/on/host>:</path/on/container> <image-name>

Look at logs

docker logs <name>
docker logs -f <name> # Follow
docker logs -t <name> # Timestamp

Network

docker network create myNetwork

Running the image on myNetwork with myNetworkID which can be used to connect to the image.

docker run -d --network myNetwork --networkAlias myNetworkID <image-name>