Day 20 Docker Cheat-Sheet: Key Commands and Tips

Day 20 Docker Cheat-Sheet: Key Commands and Tips

🐳Docker Commands

🔶Basic Commands

  • docker --version: Display the Docker version

  • docker info: Show detailed information about the Docker installation.

🔶Container Management

  • docker run <options> <port> <image_name>: Run a new container from a Docker image.

  • docker ps: List running containers.

  • docker ps -a: List all containers (including dead ones).

  • docker stop <container_id/name>: Stop a running container.

  • docker start <container_id/name>: Start a stopped container.

  • docker restart <container_id/name>: Restart a container.

  • docker rm <container_id/name>: Remove a stopped container.

  • docker rmi <image_id>: Remove a Docker image.

🔶Image Management

  • docker images: List all Docker images.

  • docker pull <image_id>: Pull an image from a Docker registry.

  • docker build -t <image_id>: Build a Docker image from a Dockerfile

  • docker tag <source_img> <destination_img>: Tag an image with a new name

  • docker push <img>: Push an image to a Docker registry.

🔶Viewing Logs and Executing Commands

  • docker logs <container_id/name>: View the logs of a container.

  • docker exec -it <container_id/name> /bin/bash: Run a command in a running container.

  • docker inspect <container_id/name>: Return low-level information about a container.

🔶Network Management

  • docker network ls: List all networks.

  • docker network create <network_name>: Create a new network.

  • docker network rm <network_name>: Remove a network.

🔶Volume Management

  • docker volume ls: List all volumes.

  • docker volume create <volume_name>: Create a new volume.

  • docker volume rm <volume_name>: Remove a volume.

📦Docker Compose Commands

🔷Basic Commands

  • docker-compose --version: Display the Docker Compose version installed

  • docker-compose up: Create and start containers defined in the docker-compose.yml file.

  • docker-compose down: Stop and remove containers, networks, and volumes defined in the docker-compose.yml file.

🔷Service Management

  • docker-compose ps: List containers defined in the docker-compose.yml file.

  • docker-compose start: Start services defined in the docker-compose.yml file.

  • docker-compose stop: Stop services defined in the docker-compose.yml file.

  • docker-compose restart: Restart services defined in the docker-compose.yml file.

  • docker-compose rm: Remove stopped service containers.

🔷Logs and Configuration

  • docker-compose logs <service>: View logs for a service.

  • docker-compose config: Validate and view the Compose file configuration.

🔷Scaling Services

  • docker-compose scale <service>=<number>: Scale a service to the specified number of instances.

🔷Running Commands in Services

  • docker-compose exec <service> <command>: Execute a command in a running service container.

✨Conclusion

With this comprehensive cheat sheet, we're well-equipped to efficiently handle Docker and Docker Compose commands. This will help us to build, deploy, and manage containerised applications.