20. Docker Cheat Sheet:

Sunil PrasadSunil Prasad
2 min read

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:

  1. Pull an Image:docker pull <image_name>This command fetches a Docker image from a registry, such as Docker Hub.

  2. List Downloaded Images:docker imagesDisplays a list of locally stored Docker images.

  3. Remove an Image:docker rmi <image_name or image_id>Deletes a Docker image from the local machine.

Docker Volumes:

  1. Create a Docker Volume:docker volume create <volume_name>Creates a Docker volume.

  2. 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.

  3. Inspect a Volume:docker volume inspect <volume_name>Provides detailed information about a Docker volume.

Container Lifecycle:

  1. Run a Container: docker run <options> <image_name>Starts a new container instance from a Docker image.

  2. List Running Containers: docker ps Shows a list of currently running containers.

  3. List All Containers: docker ps -a Displays all containers, including stopped ones.

  4. Stop a Running Container: docker stop <container_id or container_name>Halts a running container.

  5. Remove a Container: docker rm <container_id or container_name> Deletes a stopped container.

Container Interaction:

  1. Execute Commands Inside a Container: docker exec -it <container_id or container_name> <command>Allows you to run commands inside a running container.

  2. Attach to a Running Container: docker attach <container_id or container_name>Attaches your terminal to a running container.

Docker Compose Commands:

  1. Compose Up: docker-compose up Builds and starts containers based on the docker-compose.yml file.

  2. Compose Down: docker-compose down Stops and removes containers, networks, and volumes defined in the docker-compose.yml file.

  3. Compose Logs: docker-compose logs Displays log output from services defined in docker-compose.yml file.

  4. Scale Services: docker-compose scale <service_name>=<num_of_instances>Scales the number of containers for a specific service.

Docker Networking:

  1. List Networks: docker network ls Shows a list of Docker networks.

  2. Inspect a Network: docker network inspect <network_name>Provides detailed information about a Docker network.

  3. Create a Network: docker network create <network_name>Creates a new Docker network.

Miscellaneous:

  1. Docker Version: docker version Displays the Docker version information.

  2. Docker Info: docker info Shows system-wide information about Docker.

  3. 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..

0
Subscribe to my newsletter

Read articles from Sunil Prasad directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Sunil Prasad
Sunil Prasad

Aspiring Devops Engineer who have proficient knowledge AWS || LINUX || GIT || GITHUB || ANSIBLE || DOCKER || TERRAFORM || JENKINS || KUBERNETES || PROMETHEUS || GRAFANA || UBUNTU/REDHAT || PYTHON ||