# Day 20 Task : Docker commands Cheat-Sheet.

### ***<mark>Docker commands:</mark>***

### **<mark>Docker Management Commands:</mark>**

* **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 &lt;image\_name&gt;**: Search for Docker images in the Docker Hub registry.
    
* **docker pull &lt;image\_name&gt;**: Download a Docker image from a registry.
    
* **docker rmi &lt;image\_name&gt;**: 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.
    

### **<mark>Docker Container Lifecycle:</mark>**

* **docker run &lt;image\_name&gt;**: Create and start a container from an image.
    
* **docker start &lt;container\_id&gt;**: Start a stopped container.
    
* **docker stop &lt;container\_id&gt;**: Stop a running container.
    
* **docker restart &lt;container\_id&gt;**: Restart a running or stopped container.
    
* **docker pause &lt;container\_id&gt;**: Pause all processes within a container.
    
* **docker unpause &lt;container\_id&gt;**: Unpause a paused container.
    
* **docker kill &lt;container\_id&gt;**: Send a SIGKILL signal to a container (force stop).
    
* **docker rm &lt;container\_id&gt;**: Remove a stopped container.
    
* **docker container inspect &lt;container\_id&gt;**: Display detailed information about a container.
    

### **<mark>Docker Image and Container Customization:</mark>**

* **docker build -t &lt;image\_name&gt;:&lt;tag&gt; &lt;path\_to\_dockerfile&gt;**: Build a Docker image from a Dockerfile.
    
* **docker commit &lt;container\_id&gt; &lt;new\_image\_name&gt;:&lt;tag&gt;**: Create a new image from a container's changes.
    
* **docker exec -it &lt;container\_id&gt; &lt;command&gt;**: Execute a command inside a running container.
    
* **docker cp &lt;local\_path&gt; &lt;container\_id&gt;:&lt;container\_path&gt;**: Copy files between the host and a container.
    
* **docker logs &lt;container\_id&gt;**: Fetch the logs of a container.
    
* **docker rename &lt;old\_container\_name&gt; &lt;new\_container\_name&gt;**: Rename a container.
    
* **docker update --memory &lt;memory\_limit&gt; &lt;container\_id&gt;**: Update the memory limit of a running container.
    

### **<mark>Docker Volume and Network Management:</mark>**

* **docker volume ls**: List Docker volumes.
    
* **docker volume create &lt;volume\_name&gt;**: Create a Docker volume.
    
* **docker volume rm &lt;volume\_name&gt;**: Remove a Docker volume.
    
* **docker network ls**: List Docker networks.
    
* **docker network create &lt;network\_name&gt;**: Create a Docker network.
    
* **docker network rm &lt;network\_name&gt;**: Remove a Docker network.
    

### **<mark>Docker Compose:</mark>**

* **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.
    

### **<mark>Docker Compose:</mark>**

* **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 &lt;service\_name&gt; &lt;command&gt;**: Execute a command inside a running service container.
    

### **<mark>Docker Volume and Bind Mounts:</mark>**

* **docker volume ls**: List Docker volumes.
    
* **docker volume create &lt;volume\_name&gt;**: Create a Docker volume.
    
* **docker volume rm &lt;volume\_name&gt;**: Remove a Docker volume.
    
* **docker run -v &lt;host\_path&gt;:&lt;container\_path&gt; &lt;image\_name&gt;**: Mount a host directory or file as a volume in the container.
    
* **docker run -v &lt;volume\_name&gt;:&lt;container\_path&gt; &lt;image\_name&gt;**: Mount a Docker volume in the container.
    

### **<mark>Docker Network Management:</mark>**

* **docker network ls**: List Docker networks.
    
* **docker network create &lt;network\_name&gt;**: Create a Docker network.
    
* **docker network rm &lt;network\_name&gt;**: Remove a Docker network.
    
* **docker network inspect &lt;network\_name&gt;**: Display detailed information about a Docker network.
    
* **docker run --network=&lt;network\_name&gt; &lt;image\_name&gt;**: Connect a container to a specific network.
    

### **<mark>Docker Registry Interaction:</mark>**

* **docker login**: Log in to a Docker registry.
    
* **docker logout**: Log out from a Docker registry.
    
* **docker tag &lt;source\_image&gt;:&lt;source\_tag&gt; &lt;registry\_url&gt;/&lt;image\_name&gt;:&lt;tag&gt;**: Tag an image for a private registry.
    
* **docker push &lt;registry\_url&gt;/&lt;image\_name&gt;:&lt;tag&gt;**: Push an image to a private registry.
    
* **docker pull &lt;registry\_url&gt;/&lt;image\_name&gt;:&lt;tag&gt;**: Pull an image from a private registry.
    

### **<mark>Docker System and Troubleshooting:</mark>**

* **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 &lt;container\_id&gt;**: Display live stream of container resource usage statistics.
    
* **docker logs &lt;container\_id&gt;**: Fetch the logs of a container.
    

### **<mark>Docker Security:</mark>**

* **docker scan &lt;image\_name&gt;**: Scan a Docker image for security vulnerabilities.
    
* **docker secret create &lt;secret\_name&gt; &lt;file\_path&gt;**: Create a Docker secret from a file.
    

### **<mark>Docker Build and Deployment:</mark>**

* **docker build -t &lt;image\_name&gt;:&lt;tag&gt; &lt;path\_to\_dockerfile&gt;**: Build a Docker image from a Dockerfile with a custom name and tag.
    
* **docker build -t &lt;image\_name&gt;:&lt;tag&gt; &lt;url\_to\_git\_repo&gt;**: Build a Docker image from a Dockerfile located in a Git repository.
    
* **docker run -d -p &lt;host\_port&gt;:&lt;container\_port&gt; &lt;image\_name&gt;**: Run a container and publish ports from the host to the container.
    
* **docker run -d --name &lt;container\_name&gt; &lt;image\_name&gt;:&lt;tag&gt;**: Run a container with a custom name.
    
* **docker push &lt;image\_name&gt;:&lt;tag&gt;**: Push an image to a Docker registry.
    
* **docker pull &lt;image\_name&gt;:&lt;tag&gt;**: Pull an image from a Docker registry.
    

### **<mark>Docker Container Cleanup:</mark>**

* **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.
    

### **<mark>Docker System and Information:</mark>**

* **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 &lt;image\_name&gt;**: Show the history of an image, including its layers and commands.
    

### **<mark>Docker Health Checks:</mark>**

* **docker run --health-cmd="&lt;command&gt;" &lt;image\_name&gt;**: Specify a command to run to check container health.
    
* **docker inspect --format='{{json .**[**State.Health**](http://State.Health)**.Status}}' &lt;container\_id&gt;**: Check the health status of a container.
    
* **docker ps --filter "health=healthy"**: List containers that are in a healthy state.
    

Thanks for reading.
