Images
-
Build an image from a Dockerfile:
docker build -t <image_name> .
docker images
docker rmi <image_name>
-
Remove all unused images:
docker image prune
Containers
-
Create and run a container from an image:
docker run --name <container_name> <image_name>
-
Run a container in the background:
docker run -d <image_name>
-
Start or stop an existing container:
docker start|stop <container_name>
-
Remove a stopped container:
docker rm <container_name>
-
Open a shell inside a running container:
docker exec -it <container_name> sh
-
Fetch and follow the logs of a container:
docker logs -f <container_name>
General Commands
docker -d
-
Display system-wide information:
docker info
docker --help
Docker Hub
docker login -u <username>
-
Publish an image to Docker Hub:
docker push <username>/<image_name>
-
Pull an image from Docker Hub:
docker pull <image_name>
Advanced Docker CLI Commands
Networking
docker network create <network_name>
docker network ls
-
Connect a container to a network:
docker network connect <network_name> <container_name>
-
Disconnect a container from a network:
docker network disconnect <network_name> <container_name>
Volumes
docker volume create <volume_name>
docker volume ls
docker volume rm <volume_name>
docker volume inspect <volume_name>
Compose
-
Start services defined in a docker-compose.yml file:
docker-compose up
-
Stop services defined in a docker-compose.yml file:
docker-compose down
docker-compose run <service_name>
Swarm
docker swarm init
docker swarm join --token <token> <manager_ip>:<port>
docker node ls
-
Deploy a stack in swarm mode:
docker stack deploy -c <compose_file> <stack_name>
Security
-
Scan an image for vulnerabilities:
docker scan <image_name>
docker trust sign <image_name>
export DOCKER_CONTENT_TRUST=1
Resource Management
-
Limit container memory usage:
docker run -m <memory_limit> <image_name>
-
Limit container CPU usage:
docker run --cpus=<cpu_limit> <image_name>
Ref: Docker CLI Cheat Sheet
Top comments (0)