# Day 20 Task: Cheat-Sheet for Docker

## **Docker Commands Cheat-Sheet:**

1. **Docker Image Management:**
    
    * `docker pull <image_name>`**:** Pull an image from Docker Hub.
        
    * `docker build -t <image_name> .`**:** Build a Docker image from a Dockerfile in the current directory.
        
    * `docker images`: List all available Docker images.
        
    * `docker rmi <image_id>`: Remove a Docker image.
        
2. **Container Management:**
    
    * `docker run -d --name <container_name> <image_name>`: Run a Docker container in the background.
        
    * `docker ps`: List all running containers.
        
    * `docker ps -a`: List all containers (including stopped ones).
        
    * `docker start <container_id>`: Start a stopped container.
        
    * `docker stop <container_id>`: Stop a running container.
        
    * `docker rm <container_id>`: Remove a stopped container.
        
3. **Logs and Inspection:**
    
    * `docker logs <container_id>`: View container logs.
        
    * `docker inspect <container_id>`: Get detailed information about a container.
        
4. **Interactive Shells:**
    
    * `docker exec -it <container_id> /bin/bash`: Start an interactive shell inside a running container.
        
5. **Port Mapping:**
    
    * `docker run -p <host_port>:<container_port> <image_name>`: Map a container's port to a host port.
        
6. **Volume Management:**
    
    * `docker volume create <volume_name>`: Create a Docker volume.
        
    * `docker run -v <volume_name>:<container_path> <image_name>`: Mount a volume to a container.
        
    * `docker volume ls`: List Docker volumes.
        
    * `docker volume create <volume>`: Create a named Docker volume.
        
    * `docker volume inspect <volume>`: Display detailed information about a volume.
        
    * `docker run -v <volume>:<container-path>`: Mount a volume into a container.
        
7. **Networks:**
    
    * `docker network ls`: List Docker networks.
        
    * `docker network create <network_name>`: Create a custom Docker network.
        
    * `docker network connect <network_name> <container_id>`: Connect a container to a network.
        

## **Docker Compose:**

**Docker-Compose Commands Cheat-Sheet:**

1. **Compose Up and Down:**
    
    * `docker-compose up -d`: Start services defined in the `docker-compose.yml` file in detached mode.
        
    * `docker-compose down`: Stop and remove containers defined in the `docker-compose.yml` file.
        
2. **Logs and Inspection:**
    
    * `docker-compose logs`: View logs for all services.
        
    * `docker-compose ps`: List the status of containers in the Compose project.
        
    * `docker-compose exec <service_name> /bin/bash`: Start an interactive shell in a service container.
        
3. **Scaling Services:**
    
    * `docker-compose up -d --scale <service_name>=<number_of_instances>`: Scale a service to run multiple instances.
        
4. **Building and Rebuilding:**
    
    * `docker-compose build`: Build or rebuild services as defined in the `docker-compose.yml` file.
        
5. **Environment Variables:**
    
    * Define environment variables in the `docker-compose.yml` file under the `environment` key for a service.
        
6. **Volumes and Networks:**
    
    * Define volumes and custom networks in the `docker-compose.yml` file for services.
        

This cheat-sheet should help you work with Docker and Docker-Compose effectively and serve as a quick reference for various common tasks in container management and orchestration.
