Here's a Docker cheatsheet tailored for DevOps tasks:
Images:
Build an image from a Dockerfile:
docker build -t <image-name> <path-to-dockerfile>
Tag an image:
docker tag <image-id> <new-repo>:<tag>
Containers:
Run a detached container with a specific name:
docker run -d --name <container-name> <image-name>
Run a container with environment variables:
docker run -e VAR_NAME=var_value <image-name>
View container logs:
docker logs <container-id>
Inspect container details:
docker inspect <container-id>
Networking:
Expose a port when running a container:
docker run -p <host-port>:<container-port> <image-name>
Create a custom bridge network:
docker network create --driver bridge <network-name>
Connect a container to multiple networks:
docker network connect <network-name> <container-id>
Volumes:
Mount a host directory into a container:
docker run -v /host/path:/container/path <image-name>
Mount a named volume:
docker run -v <volume-name>:/container/path <image-name>
Docker Compose:
Specify Docker Compose file:
docker-compose -f <docker-compose-file> up
Scale services with Docker Compose:
docker-compose up --scale <service-name>=<num-instances>
Stop and remove containers, networks, and volumes:
docker-compose down
Registry:
Push image to Docker Hub:
docker push <image-name>
Push image to a private registry:
docker push <registry-url>/<image-name>:<tag>
Pull image from a private registry:
docker pull <registry-url>/<image-name>:<tag>
Swarm (Orchestration):
Initialize a Docker Swarm:
docker swarm init
Join a node to a Swarm:
docker swarm join --token <token> <manager-ip>:<manager-port>
Deploy a service in Swarm:
docker service create --name <service-name> <image-name>
Miscellaneous:
Prune unused resources:
docker system prune -a
Check Docker version:
docker version
Monitor resource usage:
docker stats <container-id>
Day 20 of #90daysofDevOps
Thanks for reading
Follow me for more about DevOps♾️........
________________________________________________________________________________
#90daysHardChallenge
#Cloudcomputing
#DevOps
#Python
#TrainWithShubham