Docker is like a super tool that helps developers put their apps in containers. It's great for everyone, whether you're just starting out or want to get better at Docker. This cheat sheet will help you with installing Docker, managing volumes (like extra storage for your containers), handling images (like app blueprints), and doing things with containers (like starting, stopping, and removing them).
๐ Image Management:
Build an image from a Dockerfile:
docker build -t <image_name> <path_to_Dockerfile>
List all images:
docker images
Pull an image from Docker Hub:
docker pull <image_name>
Remove an image:
docker rmi <image_name>
๐ Docker Container:
Run a container:
docker run <image_name>
List running containers:
docker ps
List all containers (including stopped ones):
docker ps -a
Start a stopped container:
docker start <container_id>
Stop a running container:
docker stop <container_id>
Remove a container:
docker rm <container_id>
๐ Docker Volume:
Create a volume:
docker volume create <volume_name>
List volumes:
docker volume ls
Inspect a volume:
docker volume inspect <volume_name>
Remove a volume:
docker volume rm <volume_name>
๐ Docker Networking:
List networks:
docker network ls
Inspect a network:
docker network inspect <network_name>
Create a network:
docker network create <network_name>
Connect a container to a network:
docker network connect <network_name> <container_id>
Disconnect a container from a network:
docker network disconnect <network_name> <container_id>
๐ Docker Compose:
Start containers defined in a Compose file:
docker-compose up
Stop containers defined in a Compose file:
docker-compose down
Build and start containers (with rebuilding if needed):
docker-compose up --build
List containers managed by Compose:
docker-compose ps
Restart containers:
docker-compose restart
Stop and remove containers:
docker-compose down --volumes
This cheat sheet covers essential Docker commands for image management, container operations, volume handling, networking, and Docker Compose usage. Feel free to refer back to it whenever you need a quick reference!
ย