Day 20 Task : Docker commands Cheat-Sheet.

Docker commands:
Docker Management Commands:
docker version: Show the Docker version information.
docker info: Display system-wide information about Docker.
docker images: List all local Docker images.
docker ps: List running containers.
docker ps -a: List all containers (including stopped ones).
docker search <image_name>: Search for Docker images in the Docker Hub registry.
docker pull <image_name>: Download a Docker image from a registry.
docker rmi <image_name>: Remove a local Docker image.
docker image prune: Remove unused Docker images.
docker container prune: Remove stopped containers.
docker volume prune: Remove unused Docker volumes.
docker network prune: Remove unused Docker networks.
Docker Container Lifecycle:
docker run <image_name>: Create and start a container from an image.
docker start <container_id>: Start a stopped container.
docker stop <container_id>: Stop a running container.
docker restart <container_id>: Restart a running or stopped container.
docker pause <container_id>: Pause all processes within a container.
docker unpause <container_id>: Unpause a paused container.
docker kill <container_id>: Send a SIGKILL signal to a container (force stop).
docker rm <container_id>: Remove a stopped container.
docker container inspect <container_id>: Display detailed information about a container.
Docker Image and Container Customization:
docker build -t <image_name>:<tag> <path_to_dockerfile>: Build a Docker image from a Dockerfile.
docker commit <container_id> <new_image_name>:<tag>: Create a new image from a container's changes.
docker exec -it <container_id> <command>: Execute a command inside a running container.
docker cp <local_path> <container_id>:<container_path>: Copy files between the host and a container.
docker logs <container_id>: Fetch the logs of a container.
docker rename <old_container_name> <new_container_name>: Rename a container.
docker update --memory <memory_limit> <container_id>: Update the memory limit of a running container.
Docker Volume and Network Management:
docker volume ls: List Docker volumes.
docker volume create <volume_name>: Create a Docker volume.
docker volume rm <volume_name>: Remove a Docker volume.
docker network ls: List Docker networks.
docker network create <network_name>: Create a Docker network.
docker network rm <network_name>: Remove a Docker network.
Docker Compose:
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.
Docker Compose:
docker-compose build: Build or rebuild services defined in the docker-compose.yml file.
docker-compose up -d: Create and start containers in detached mode (background).
docker-compose logs: Fetch the logs of all services in the docker-compose project.
docker-compose ps: List containers status in the docker-compose project.
docker-compose stop: Stop all containers in the docker-compose project.
docker-compose down -v: Stop and remove containers, networks, and volumes in the docker-compose project.
docker-compose exec <service_name> <command>: Execute a command inside a running service container.
Docker Volume and Bind Mounts:
docker volume ls: List Docker volumes.
docker volume create <volume_name>: Create a Docker volume.
docker volume rm <volume_name>: Remove a Docker volume.
docker run -v <host_path>:<container_path> <image_name>: Mount a host directory or file as a volume in the container.
docker run -v <volume_name>:<container_path> <image_name>: Mount a Docker volume in the container.
Docker Network Management:
docker network ls: List Docker networks.
docker network create <network_name>: Create a Docker network.
docker network rm <network_name>: Remove a Docker network.
docker network inspect <network_name>: Display detailed information about a Docker network.
docker run --network=<network_name> <image_name>: Connect a container to a specific network.
Docker Registry Interaction:
docker login: Log in to a Docker registry.
docker logout: Log out from a Docker registry.
docker tag <source_image>:<source_tag> <registry_url>/<image_name>:<tag>: Tag an image for a private registry.
docker push <registry_url>/<image_name>:<tag>: Push an image to a private registry.
docker pull <registry_url>/<image_name>:<tag>: Pull an image from a private registry.
Docker System and Troubleshooting:
docker system df: Show Docker disk usage.
docker system events: Display system events such as container creation, starting, stopping, etc.
docker system info: Display system-wide information about Docker.
docker system prune: Remove unused data (containers, images, networks, and volumes).
docker stats <container_id>: Display live stream of container resource usage statistics.
docker logs <container_id>: Fetch the logs of a container.
Docker Security:
docker scan <image_name>: Scan a Docker image for security vulnerabilities.
docker secret create <secret_name> <file_path>: Create a Docker secret from a file.
Docker Build and Deployment:
docker build -t <image_name>:<tag> <path_to_dockerfile>: Build a Docker image from a Dockerfile with a custom name and tag.
docker build -t <image_name>:<tag> <url_to_git_repo>: Build a Docker image from a Dockerfile located in a Git repository.
docker run -d -p <host_port>:<container_port> <image_name>: Run a container and publish ports from the host to the container.
docker run -d --name <container_name> <image_name>:<tag>: Run a container with a custom name.
docker push <image_name>:<tag>: Push an image to a Docker registry.
docker pull <image_name>:<tag>: Pull an image from a Docker registry.
Docker Container Cleanup:
docker container prune: Remove stopped containers.
docker system prune -a: Remove all unused data (containers, images, networks, and volumes).
docker volume prune: Remove unused Docker volumes.
docker network prune: Remove unused Docker networks.
Docker System and Information:
docker info: Display system-wide information about Docker.
docker version: Show the Docker version information.
docker events: Display real-time events from the server.
docker stats: Display a live stream of container resource usage statistics.
docker ps -a --no-trunc: Show all containers and their complete command lines.
docker history <image_name>: Show the history of an image, including its layers and commands.
Docker Health Checks:
docker run --health-cmd="<command>" <image_name>: Specify a command to run to check container health.
docker inspect --format='{{json .State.Health.Status}}' <container_id>: Check the health status of a container.
docker ps --filter "health=healthy": List containers that are in a healthy state.
Thanks for reading.



