# Useful Docker Commands In daily use

### Docker Basics

1. **docker version**
    
    * Shows the Docker version installed on your system.
        
    * ```plaintext
        docker version
        ```
        
2. **docker info**
    
    * Displays system-wide information about Docker, including number of containers, images, and other details.
        
        ```plaintext
        docker info
        ```
        
3. **docker help**
    
    * Provides help on using Docker commands.
        
        ```python
        docker help
        ```
        

### Working with Images

4. **docker pull**
    
    * Downloads an image from a Docker registry (e.g., Docker Hub).
        
        ```python
        docker pull <image_name>
        ```
        
5. **docker images**
    
    * Lists all the images on your local machine.
        
        ```python
        docker images
        ```
        
6. **docker rmi**
    
    * Removes one or more images from your local machine.
        
    * ```python
        docker rmi <image_id>
        ```
        
7. **docker tag**
    
    * Tags an image with a new name.
        
        ```python
        docker tag <existing_image> <new_image:tag>
        ```
        
8. **docker build**
    
    * Builds an image from a Dockerfile.
        
        ```python
        docker build -t <image_name:tag> <path_to_dockerfile>
        ```
        
9. **docker push**
    
    * Uploads an image to a Docker registry.
        
        ```python
        docker push <image_name:tag>
        ```
        

### Working with Containers

10. **docker run**
    
    * Runs a container from an image.
        
        ```python
        docker run -d --name <container_name> <image_name>
        ```
        
11. **docker ps**
    
    * Lists all running containers.
        
        ```python
        docker ps
        ```
        
12. **docker ps -a**
    
    * Lists all containers, including stopped ones.
        
        ```python
        docker ps -a
        ```
        
13. **docker stop**
    
    * Stops a running container.
        
        ```python
        docker stop <container_id>
        ```
        
14. **docker start**
    
    * Starts a stopped container.
        
        ```python
        docker start <container_id>
        ```
        
15. **docker restart**
    
    * Restarts a container.
        
        ```python
        docker restart <container_id>
        ```
        
16. **docker rm**
    
    * Removes a container.
        
        ```python
        docker rm <container_id>
        ```
        
17. **docker logs**
    
    * Displays the logs of a container.
        
        ```python
        docker logs <container_id>
        ```
        
18. **docker exec**
    
    * Runs a command in a running container.
        
        ```python
        docker exec -it <container_id> <command>
        ```
        
19. **docker attach**
    
    * Attaches your terminal to a running container.
        
        ```python
        docker attach <container_id>
        ```
        

### Container Networking

20. **docker network ls**
    
    * Lists all Docker networks.
        
        ```python
        docker network ls
        ```
        
21. **docker network create**
    
    * Creates a new Docker network.
        
        ```python
        docker network create <network_name>
        ```
        
22. **docker network inspect**
    
    * Displays detailed information about a network.
        
        ```python
        docker network inspect <network_name>
        ```
        
23. **docker network connect**
    
    * Connects a container to a network.
        
        ```python
        docker network connect <network_name> <container_id>
        ```
        
24. **docker network disconnect**
    
    * Disconnects a container from a network.
        
        ```python
        docker network disconnect <network_name> <container_id>
        ```
        

### Docker Volumes

25. **docker volume ls**
    
    * Lists all Docker volumes.
        
        ```python
        docker volume ls
        ```
        
26. **docker volume create**
    
    * Creates a new Docker volume.
        
        ```python
        docker volume create <volume_name>
        ```
        
27. **docker volume inspect**
    
    * Displays detailed information about a volume.
        
        ```python
        docker volume inspect <volume_name>
        ```
        
28. **docker volume rm**
    
    * Removes a Docker volume.
        
        ```python
        docker volume rm <volume_name>
        ```
        

### Docker Compose

29. **docker-compose up**
    
    * Builds, (re)creates, starts, and attaches to containers for a service defined in a `docker-compose.yml` file.
        
        ```python
        docker-compose up
        ```
        
30. **docker-compose down**
    
    * Stops and removes containers, networks, volumes, and images created by `docker-compose up`.
        
        ```python
        docker-compose down
        ```
        
31. **docker-compose ps**
    
    * Lists containers started by Docker Compose.
        
        ```python
        docker-compose ps
        ```
        
32. **docker-compose logs**
    
    * Displays log output from services managed by Docker Compose.
        
        ```python
        docker-compose logs
        ```
        
33. **docker-compose exec**
    
    * Executes a command in a running service container.
        
        ```python
        docker-compose exec <service_name> <command>
        ```
        

### Cleanup Commands

34. **docker system prune**
    
    * Removes all unused containers, networks, images (both dangling and unreferenced), and optionally, volumes.
        
        ```python
        docker system prune
        ```
        
35. **docker container prune**
    
    * Removes all stopped containers.
        
        ```python
        docker container prune
        ```
        
36. **docker image prune**
    
    * Removes unused images.
        
        ```python
        docker image prune
        ```
        
37. **docker volume prune**
    
    * Removes all unused volumes.
        
        ```python
        docker volume prune
        ```
        

### Inspecting and Debugging

38. **docker inspect**
    
    * Returns low-level information about Docker objects.
        
        ```python
        docker inspect <container_id or image_id>
        ```
        
39. **docker diff**
    
    * Inspects changes to files or directories on a container’s filesystem.
        
        ```python
        docker diff <container_id>
        ```
        

### Security

40. **docker scan**
    
    * Scans your Docker images for vulnerabilities.
        
        ```python
        docker scan <image_name>
        ```
        

By mastering these commands, you can effectively manage Docker images, containers, networks, volumes, and more, enhancing your ability to deploy and maintain containerized applications.
