Docker is a powerful platform that enables developers to create, deploy, and run applications in containers. Whether you're a beginner or looking to enhance your Docker skills, this cheat sheet will guide you through Docker installation, volume management, image handling, and container operations.
Image Management:
Pull an Image:docker pull <image_name>This command fetches a Docker image from a registry, such as Docker Hub.
List Downloaded Images:docker imagesDisplays a list of locally stored Docker images.
Remove an Image:docker rmi <image_name or image_id>Deletes a Docker image from the local machine.
Docker Volumes:
Create a Docker Volume:docker volume create <volume_name>Creates a Docker volume.
Run a Container with a Volume:docker run -v <volume_name>:<container_directory> <image_name>Attaches a volume to a container, preserving data in the container's directory on the volume.
Inspect a Volume:docker volume inspect <volume_name>Provides detailed information about a Docker volume.
Container Lifecycle:
Run a Container: docker run <options> <image_name>Starts a new container instance from a Docker image.
List Running Containers: docker ps Shows a list of currently running containers.
List All Containers: docker ps -a Displays all containers, including stopped ones.
Stop a Running Container: docker stop <container_id or container_name>Halts a running container.
Remove a Container: docker rm <container_id or container_name> Deletes a stopped container.
Container Interaction:
Execute Commands Inside a Container: docker exec -it <container_id or container_name> <command>Allows you to run commands inside a running container.
Attach to a Running Container: docker attach <container_id or container_name>Attaches your terminal to a running container.
Docker Compose Commands:
Compose Up: docker-compose up Builds and starts containers based on the docker-compose.yml file.
Compose Down: docker-compose down Stops and removes containers, networks, and volumes defined in the docker-compose.yml file.
Compose Logs: docker-compose logs Displays log output from services defined in docker-compose.yml file.
Scale Services: docker-compose scale <service_name>=<num_of_instances>Scales the number of containers for a specific service.
Docker Networking:
List Networks: docker network ls Shows a list of Docker networks.
Inspect a Network: docker network inspect <network_name>Provides detailed information about a Docker network.
Create a Network: docker network create <network_name>Creates a new Docker network.
Miscellaneous:
Docker Version: docker version Displays the Docker version information.
Docker Info: docker info Shows system-wide information about Docker.
Clean Up Docker Resources: docker system prune -a Removes stopped containers, unused networks, and dangling images.
Now that you have this comprehensive cheat sheet, you'll be well-equipped to navigate the Docker ecosystem efficiently. Feel free to share this resource with the DevOps community, and remember, continuous learning is the key to mastering Docker! Happy containerizing!
Thank you for reading this article..