Docker CLI References
Published 10 months ago.
Last updated
Init
|
|
docker init |
Make a new Docker project in the current directory. |
Build Image
docker build <options> <path-to-dockerfile>
|
|
docker build -t <the-final-image-name> . |
Build an image with a name, caching, standard build log output from a dockerfile in the same directory. |
docker build -t <the-final-image-name> --no-cache --progress=plain . |
Build an image with a name, no layer caching, with detailed build log output from a dockerfile in the same directory. |
Run Image
docker run <options> <image-name> <commands>
|
|
docker run --name <container-name> -it <image-name> |
Start a named container from a named image and open in the shell. Exit the shell with exit or ctrl+c. |
docker run --name <container-name> -it -p80:80 -d <image-name> |
Start a named container from a named image with port 80:80 in the background. |
docker run -d --name <container-name> -p 8080:8080 -e RT_WEB_PORT=8080 <image-name> |
Start a named container from a named image with port 8080:8800 in the background with the env var RT_WEB_PORT =8080 . |
Docker Compose
|
|
docker compose up -d |
Start a compose app in the background. |
docker compose up -d --build |
Start a compose app in the background and build before running. |
docker-compose down |
Stop a background compose app. |
docker compose up |
Start a compose app in the shell (foreground). |
CTR+c or type exit |
Stop a compose app in the shell. |
docker compose ps |
Inspect all running containers on the system. |
Docker Containers
|
|
docker ps |
Inspect all containers, their ports and IDs running on the system. |
Shell Access
|
|
docker exec -it <the-container-id> /bin/sh |
Ash shell (Alpin Linux) access to a running container. |
docker exec -it <the-container-id> /bin/bash |
Bash shell (Debian, Alpine, other Linux) access to a running container. |
Docker Volumes
|
|
docker volume ls |
List all Docker volumes. |
docker volume rm <the-volume-name> |
Delete a volume from the local system. |
MySQL and MariaDB
|
|
docker exec -it <the-container-id> mariadb -u root -p |
Direct MariaDB client access in a running container. |
docker exec -it <the-container-id> mysql -u root -p |
Direct MySQL client access in a running container. |
Docker Images
|
|
docker images |
List all images downloaded to the system. |
docker pull <the-image-name>:<the-image-tag> |
Download an image from Dockerhub to the system. |
docker rmi $(docker images --filter "dangling=true" -q --no-trunc) |
Remove all unused images on the system. |