Skip to main content

Command Palette

Search for a command to run...

Docker and Docker-Compose Cheat-Sheet

Day-20 #90daysofdevops

Published
β€’3 min readβ€’View as Markdown
Docker and Docker-Compose Cheat-Sheet
N

Nikhil Patil

πŸ‘¨β€πŸ’» I love Linux & DevOps! πŸ’»

🐧 LinuxπŸ‘¨β€πŸ’» | DevOps & Cloud Enthusiast | 🌍 Azure Admin | πŸ› οΈ Ansible | πŸ“‚ Git | 🐳 Docker | πŸ”‘ OpenLDAP | πŸ–₯️ System Admin | | πŸš€ Jenkins πŸ› οΈ

🏠 Pune

🌟 I'm really into using and managing computers with Linux. I also like making things work smoothly and quickly.

πŸ“– I work with Microsoft Azure, use tools like Ansible and Git to automate tasks, and make software run in containers with Docker.

πŸ”’ I handle access and security using OpenLDAP, and I'm all about keeping systems running smoothly.

🌐 Exploring opportunities in cloud and DevOps.

πŸ“§ Get in touch: nikrpatil1997@gmail.com

πŸ“Œ Introduction

We have completedβœ… the Docker hands-on and we learned something interesting from it.πŸ™Œ

Now it's time to take your Docker skills to the next level by creating a comprehensive cheat-sheet of all the commands we have learned so far. This cheat-sheet should include commands for both Docker and Docker-Compose, as well as brief explanations of their usage.

πŸ“Œ Docker and Docker-Compose Cheat-Sheet

Docker Container

  • docker ps - List the running containers

  • docker ps -a - List all the containers running and stopped

  • docker create <image name> - Create a container

  • docker create -it <image name> - Create container in interactive mode

  • docker rm <container name> - Delete container

  • docker logs <container name> - View logs of running container

  • docker port - Show port mapping for a container

  • docker stats - Show usage statistics for a container

  • docker run <image> - To run a container

  • docker run -p <host:container> <image> - map host port to container port

  • docker run -d - Run a detached container

  • docker run -it - Run an interactive process

  • docker start <container name> - start a container

  • docker stop <container name> - stop a container

  • docker kill <container name> - To kill the container

  • docker exec -it <container> <shell> - Run a shell inside container

Docker Images

  • docker build <dockerfilepath> - create image from docker file

  • docker build . - Build an image from the current path

  • docker build -t <name>:<tag> - Create image and tag it

  • docker pull <image> - Pull an image

  • docker push <image> - Push an image

  • docker images - To see docker images locally

  • docker rmi - Remove docker images

  • docker image prune - Remove all images

Docker Networking

  • docker network ls - View available network

  • docker network rm <network>- Remove a network

  • docker network inspect <network > - Show information about a network

General Commands

  • docker login - Login to the docker registry

  • docker logout - Log out of a docker registry

Docker volume

  • docker volume ls - List of volume

  • docker volume create <volume>- Create a new volume

  • docker volume inspect <volume > - To check information of volume

  • docker volume rm <volume> - Remove a volume

Docker Compose

  • docker-compose up - Start container defined in the docker-compose file

  • docker-compose up -d - Run containers in detached mode

  • docker-compose down - stop containers and remove

  • docker-compose build - Build docker image defined in the docker-compose file

  • docker-compose stop - Stop containers created by the docker-compose file

  • docker-compose logs - View all logs