Docker for DevOps Engineers: Cheat-sheet #Day-20

Nikunj VaishnavNikunj Vaishnav
2 min read

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:

LinkedIn | Twitter | GitHub

Like👍 | Share📲 | Comment💭

2
Subscribe to my newsletter

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

Written by

Nikunj Vaishnav
Nikunj Vaishnav

👋 Hi there! I'm Nikunj Vaishnav, a passionate QA engineer Cloud, and DevOps. I thrive on exploring new technologies and sharing my journey through code. From designing cloud infrastructures to ensuring software quality, I'm deeply involved in CI/CD pipelines, automated testing, and containerization with Docker. I'm always eager to grow in the ever-evolving fields of Software Testing, Cloud and DevOps. My goal is to simplify complex concepts, offer practical tips on automation and testing, and inspire others in the tech community. Let's connect, learn, and build high-quality software together! 📝 Check out my blog for tutorials and insights on cloud infrastructure, QA best practices, and DevOps. Feel free to reach out – I’m always open to discussions, collaborations, and feedback!