Day 20: Docker Cheatsheet

Day 20: Docker Cheatsheet

#90daysofdevops

ยท

4 min read

๐Ÿ’Ž Docker Commands:

  • docker run: Create and run a new container based on an image.
Example: docker run <image>
  • docker ps: List running containers.
Example: docker ps
  • docker images: List available images.
Example: docker images
  • docker pull: Download an image from a registry.
Example: docker pull <image>
  • docker build: Build an image from a Dockerfile.
Example: docker build -t <image_name> <path_to_dockerfile>
  • docker start: Start a stopped container.
Example: docker start <container>
  • docker stop: Stop a running container.
Example: docker stop <container>
  • docker restart: Restart a running container.
Example: docker restart <container>
  • docker rm: Remove a stopped container.
Example: docker rm <container>
  • docker rmi: Remove an image.
Example: docker rmi <image>
  • docker exec: Run a command inside a running container.
Example: docker exec <container> <command>
  • docker cp: Copy files/folders between a container and the local filesystem.
Example: docker cp <container>:<path_to_file> <local_path>
  • docker logs: Fetch the logs of a container.
Example: docker logs <container>
  • docker inspect: View detailed information about a container or image.
Example: docker inspect <container/image>
  • docker network ls: List Docker networks.
Example: docker network ls
  • docker network create: Create a Docker network.
Example: docker network create <network_name>
  • docker network connect: Connect a container to a network.
Example: docker network connect <network> <container>
  • docker network disconnect: Disconnect a container from a network.
Example: docker network disconnect <network> <container>

๐Ÿ’Ž Docker-Compose Commands:

  • docker-compose up: Create and start containers defined in the docker-compose.yml file.
Example: docker-compose up
  • docker-compose down: Stop and remove containers, networks, and volumes defined in the docker-compose.yml file.
Example: docker-compose down
  • docker-compose build: Build or rebuild services defined in the docker-compose.yml file.
Example: docker-compose build
  • docker-compose start: Start services defined in the docker-compose.yml file.
Example: docker-compose start
  • docker-compose stop: Stop services defined in the docker-compose.yml file.
Example: docker-compose stop
  • docker-compose restart: Restart services defined in the docker-compose.yml file.
Example: docker-compose restart
  • docker-compose ps: List containers of services defined in the docker-compose.yml file.
Example: docker-compose ps
  • docker-compose logs: Fetch the logs of services defined in the docker-compose.yml file.
Example: docker-compose logs
  • docker-compose exec: Run a command inside a running service container.
Example: docker-compose exec <service> <command>
  • docker-compose pull: Download updated images for services defined in the docker-compose.yml file.
Example: docker-compose pull
  • docker-compose rm: Remove stopped containers for services defined in the docker-compose.yml file.
Example: docker-compose rm
  • docker-compose config: Validate and view the composed configuration.
Example: docker-compose config
  • docker-compose scale: Scale services up or down.
Example: docker-compose scale <service>=<num_instances>
  • docker-compose run: Run a one-time command against a service container.
Example: docker-compose run <service> <command>
  • docker-compose pause: Pause services.
Example: docker-compose pause <service>
  • docker-compose unpause: Unpause services.
Example: docker-compose unpause <service>
  • docker-compose up -d: Create and start containers in detached mode.
Example: docker-compose up -d
  • docker-compose down -v: Stop and remove containers, networks, volumes, and images defined in the docker-compose.yml file.
Example: docker-compose down -v
  • To build an image from a Dockerfile.
docker build -t <image_name> .
  • Runs a command in a new container.
docker run -d --name <container-name> -p 80:80 <image-name>
  • Starts one or more stopped containers.
docker start <container-name>
  • Stops one or more running containers.
docker stop <container-name>
  • Pulls an image or a repository from a registry.
docker pull <image-name:tag>
  • Pushes an image or a repository to a registry.
docker push <image-name:tag>
  • Runs a command in a running container and go inside a container.
 docker exec -it <container-name or ID> bash
  • Removes one or more containers.
docker rm <container-name or ID>
  • Removes one or more images.
docker rmi <image-name>
  • Lists all the images on the local system.
docker images
  • Lists all running containers.
docker ps

Fetches the logs of a container.

docker logs <container-name or ID>
  • Returns low-level information on a container or image.
docker inspect <container-name or ID>
  • Create and start containers.
docker-compose up
  • List containers.
docker-compose ps
  • Stop and remove containers, networks, images, and volumes.
docker-compose down
  • Show logs.
docker-compose logs <service>

๐Ÿ’Ž Docker Volume:

  • Create a volume.
docker volume create <volume-name>
  • List volumes.
docker volume ls
  • Display detailed information on one or more volumes.
docker volume inspect <volume-name>
  • Remove one or more volumes.
docker volume rm <volume-name>
  • Remove all unused volumes.
docker volume prune

Thanks for reading to the end; I hope you gained some knowledge.โค๏ธ๐Ÿ™Œ

Linkedln

Twitter

Github

ย