Docker CLI
warning
This document has been translated using machine translation without human review.
What is the difference between buildx and just build?
buildx
is a command that uses BuildKit, a new, more powerful builder.
How to run multiple containers?
Use Docker Compose.
How to build an image?
Image parameters are specified in the Dockerfile file.
By default, the name "Dockerfile" is used.
docker build .
Set the image name:
docker build . --tag repo_name:image_name
Set launch arguments:
docker build . --build-arg ARG_1_NAME=ARG_1_VALUE --build-arg ARG_2_NAME=ARG_2_VALUE
Use a custom name for Dockerfile
:
docker build -f some/path/MyDockerfile
Other useful parameters:
--progress=plain
— output the entire report;--no-cache
— disable caching;--rm
— remove intermediate containers after successful build;-q
,--quiet
— quiet mode, in case of success only the image identifier will be output;
How to display the full log when creating an image?
docker build . --progress=plain
How to disable cache when creating an image?
docker build . --no-cache
How to manage a container (start/pause/restart/stop)?
docker run -d --name MY_CONTAINER -p 80:5080 -p 443:5443 -e ASPNETCORE_URLS="http://+:5080;https://+:5443" ${IMAGE_ID_OR_NAME}
-d
,--detach
— run in background mode;-e
,--env
— allows setting environment variables;-p
,--publish
— redirects ports (host_port:container_port
);--name
— sets the container name;
Standard commands start
, pause
, restart
and stop
are available:
docker start ${CONTAINER_NAME_OR_ID}
How to view container logs?
docker logs ${CONTAINER_NAME_OR_ID}
--details
— show extended data;-n
,--tail
— show N lines from the end of the log;
How to delete a container?
docker rm ${CONTAINER_NAME_OR_ID}
-f
,--force
— stop and delete, ask no questions;
How to get a list of containers?
docker ps
All containers, including stopped ones:
docker ps -a
Recently created containers:
docker ps -l
Disable truncation of long lines:
docker ps --no-trunc
To filter the output, you can use grep
(only on Linux systems):
docker ps -a | grep ${SEARCH_STRING}
How to get a list of images?
docker image list --all
-a
,--all
- all images;--no-trunc
- disable truncation of long lines;
How to view image history?
docker image history ${IMAGE_NAME_OR_ID}
How to delete an image?
docker rmi ${IMAGE_NAME_OR_ID}
How to get the image author's name?
docker inspect ${IMAGE_NAME_OR_ID}
How to view container files?
docker create --name="${CONTAINER_NAME_OR_ID}" ${IMAGE_NAME_OR_ID}
docker export ${CONTAINER_NAME_OR_ID} | tar -t
docker rm ${CONTAINER_NAME_OR_ID}
How to export a container to a file?
docker export ${CONTAINER_NAME_OR_ID} > output.tar
How to execute a command in a container?
docker run --name ${CONTAINER_NAME_OR_ID} -d -i -t ${IMAGE_NAME_OR_ID} /bin/sh
docker exec -it ${CONTAINER_NAME_OR_ID} /bin/bash
docker exec -it ${CONTAINER_NAME_OR_ID} /bin/sh
How to clean up resources?
Delete unused images, containers, and networks
docker system prune
Stop and delete EVERYTHING, EVERYTHING, EVERYTHING
docker system prune -a
Delete only unused images
docker image prune
Delete only stopped containers
docker container prune
Delete only unused volumes
docker volume prune
Delete only unused networks
docker network prune