Skip to main content

Command Palette

Search for a command to run...

Day 19: Docker Cheat-sheet

Updated
β€’2 min read
Y

I am Yashraj Singh Sisodiya, a 3rd Year CSE student at SVVV, born and raised in Shujalpur. Currently residing in Indore, I'm passionate about pursuing a career in DevOps engineering. My tech journey began with an internship at Infobyte, honing my skills as an Android Developer intern. Alongside my academic pursuits, I actively participate in co-curriculars, holding roles as Technical Lead at Abhyudaya and Cloud Lead at GDSC SVVV, while also serving as an MLSA of my college.

I have a keen interest in Cloud Computing, demonstrated through projects such as User management and Backup using shell scripting Linux, Dockerizing applications, CI/CD with Jenkins, and deploying a 3-tier application on AWS. Always eager to learn, I'm committed to expanding my knowledge and skills in the ever-evolving tech landscape.

General Usage

  • Start a container in the background:

      $ docker run -d jenkins
    
  • Start an interactive container:

      $ docker run -it ubuntu bash
    
  • Export port from a container:

      $ docker run -p 80:80 -d nginx
    
  • Start a named container:

      $ docker run --name mydb redis
    
  • Restart a stopped container:

      $ docker start mydb
    
  • Stop a container:

      $ docker stop mydb
    
  • Add metadata to a container:

      $ docker run -d --label=traefik.backend=jenkins jenkins
    

Build Images

  • Build an image from Dockerfile in the current directory:

      $ docker build --tag myimage .
    
  • Force rebuild of a Docker image:

      $ docker build --no-cache .
    
  • Convert a container to an image:

      $ docker commit c7337 myimage
    

Debug

  • Run another process in a running container:

      $ docker exec -it c7337 bash
    
  • Show live logs of a running daemon container:

      $ docker logs -f c7337
    
  • Show exposed ports of a container:

      $ docker port c7337
    

Volumes

  • Create a local volume:

      $ docker volume create --name myvol
    
  • Mounting a volume on container start:

      $ docker run -v myvol:/data redis
    
  • Destroy a volume:

      $ docker volume rm myvol
    
  • List volumes:

      $ docker volume ls
    

Manage Containers

  • List running containers:

      $ docker ps
    
  • List all containers (running & stopped):

      $ docker ps -a
    
  • Delete all stopped containers:

      $ docker rm $(docker ps --filter status=exited -q)
    
  • Start a container automatically removed on stop:

      $ docker run --rm ubuntu bash
    
  • Query a specific metadata of a running container:

      $ docker inspect -f '{{ .NetworkSettings.IPAddress }}' c7337
    

Networking

  • Create a local network:

      $ docker network create mynet
    
  • Attach a container to a network on start:

      $ docker run -d --net mynet redis
    
  • Connect a running container to a network:

      $ docker network connect mynet c7337
    
  • Disconnect a container from a network:

      $ docker network disconnect mynet c7337
    
  • List all containers with a specific label:

      $ docker ps --filter label=traefik.backend
    

Cleanup

  • Remove all unused images:

      $ docker rmi $(docker images -q)
    

More from this blog

Mastering DevOps: A Comprehensive Guide to Becoming a DevOps Engineer

39 posts

πŸš€ Welcome to the world of DevOps with Yashraj! 🌐

Hey tech enthusiasts! πŸ‘‹ I'm Yashraj, a dedicated third-year student pursuing Computer Science Engineering at SVVV Indore. Currently, I'm honing my πŸš€ Welcome to the world of DevOps with Yashraj! 🌐

Hey tech enthusiasts! πŸ‘‹ I'm Yashraj, a dedicated third-year student pursuing Computer Science Engineering at SVVV Indore. Currently, I'm honing my skills in the realm of DevOps, fueled by my passion for technology and innovation.

πŸ› οΈ My Tech Arsenal:

  • Docker
  • Linux
  • Kubernetes
  • Jenkins
  • AWS
  • Python
  • Java
  • Prometheus
  • Grafana
  • Ansible
  • Terraform

Join me in exploring the fascinating landscape of AWS DevOps technology. Let's embark on a journey of continuous learning and growth, embracing new challenges with enthusiasm and determination!

🀝 Connect with me for:

  • Engaging discussions
  • Shared learning experiences
  • Collaborative learning opportunities

Follow my journey on Twitter and LinkedIn for daily insights and tech updates. Together, let's harness the power of DevOps to build, automate, and innovate our way to success! πŸš€ #DevOps #AWS #TechEnthusiast #InnovationJourney #90DaysOfDevOps