# Day20 of 90DaysOfDevOps

### **Docker & Docker Compose Cheat-Sheet**

#### **1\. Basic Docker Commands**

| **Command** | **Description** |
| --- | --- |
| `docker --version` | Check the installed Docker version. |
| `docker info` | Display detailed information about the Docker environment. |
| `docker images` | List all Docker images on the local machine. |
| `docker pull <image_name>` | Download an image from Docker Hub. |
| `docker run <image_name>` | Create and start a container from an image. |
| `docker ps` | Show all currently running containers. |

---

#### **2\. Container Management**

| **Command** | **Description** |
| --- | --- |
| `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. |
| `docker logs <container_id>` | View logs of a container. |

---

#### **3\. Docker Images**

| **Command** | **Description** |
| --- | --- |
| `docker build -t <image_name>:<tag> .` | Build a Docker image from a Dockerfile. |
| `docker rmi <image_id>` | Remove an image by its ID. |
| `docker tag <image_id> <repo_name>:<tag>` | Tag an image for pushing to a repository. |

---

#### **4\. Networking**

| **Command** | **Description** |
| --- | --- |
| `docker network ls` | List all Docker networks. |
| `docker network create <network_name>` | Create a new Docker network. |
| `docker network inspect <network_name>` | Inspect a specific Docker network. |

---

#### **5\. Docker Compose : Any one command will work based on your Docker compose version.**

| **Command** | **Description** |
| --- | --- |
| `docker compose --version`/`docker-compose --version` | Check the installed Docker Compose version. |
| `docker compose up`/`docker-compose up` | Start all services defined in the `docker-compose.yml`. |
| `docker compose down`/`docker-compose down` | Stop and remove all containers defined in `docker-compose.yml`. |
| `docker compose logs`/`docker-compose logs` | View logs for all services. |

---

#### **6\. Troubleshooting**

| **Command** | **Description** |
| --- | --- |
| `docker inspect <container_id>` | Display detailed information about a container. |
| `docker exec -it <container_id> bash` | Open a shell session in a running container. |
| `docker system prune` | Clean up unused Docker objects (images, containers, networks). |
