Docker for DevOps Engineers: Cheat-sheet #Day-20
Docker Basics for DevOps Engineers: Quick Guide
Docker Basics
Images
List images:
docker images
Pull an image:
docker pull [image:tag]
Build an image:
docker build -t [name:tag] [path]
Remove an image:
docker rmi [image_id]
Containers
List running containers:
docker ps
List all containers:
docker ps -a
Run a container:
docker run [options] [image:tag]
-d
: Run container in background (detached mode)-p [host_port:container_port]
: Map port--name [container_name]
: Name the container-v [host_dir:container_dir]
: Mount a volume-e [env_var=value]
: Set environment variable--rm
: Remove container after it stops
Stop a container:
docker stop [container_id/name]
Start a container:
docker start [container_id/name]
Remove a container:
docker rm [container_id/name]
View container logs:
docker logs [container_id/name]
Execute command in running container:
docker exec -it [container_id/name] [command]
Networks
List networks:
docker network ls
Create network:
docker network create [network_name]
Connect container to network:
docker network connect [network_name] [container_id/name]
Disconnect container from network:
docker network disconnect [network_name] [container_id/name]
Inspect network:
docker network inspect [network_name]
Remove network:
docker network rm [network_name]
Volumes
List volumes:
docker volume ls
Create volume:
docker volume create [volume_name]
Inspect volume:
docker volume inspect [volume_name]
Remove volume:
docker volume rm [volume_name]
Docker Compose
Start services defined in docker-compose.yml:
docker-compose up
-d
: Run containers in the background
Stop services:
docker-compose down
Rebuild images:
docker-compose build
View logs:
docker-compose logs
-f
: Follow log output
Scale services:
docker-compose scale [service=num]
List services:
docker-compose ps
Execute command in service:
docker-compose exec [service] [command]
Conclusion
Docker is an essential tool for DevOps engineers, streamlining the process of developing, shipping, and running applications. This cheat-sheet provides a quick reference to fundamental Docker commands, covering images, containers, networks, volumes, and Docker Compose. By mastering these commands, DevOps professionals can efficiently manage their containerized environments, ensuring smooth and consistent application deployment and operation.
Connect and Follow:
Like👍 | Share📲 | Comment💭