# Cheat sheet of important Docker commands

Before jumping into the topic, If you're new to Docker and looking for effective ways to manage Docker containers, you're in luck! Docker commands provide a solution to help you achieve just that.

Docker is a widely used platform that enables developers to package their applications, along with their dependencies and configurations, into containers that can seamlessly run across various environments.

With Docker commands, you gain the power to effortlessly **create**, **run**, **stop**, **remove**, and manage Docker containers. These commands prove to be invaluable in automating and streamlining the process of deploying and managing your applications within a containerized environment. By leveraging Docker commands, you can ensure a smooth and efficient workflow for your container-based applications.

You can easily visit the [Docker Documentation](https://docs.docker.com/get-started/overview/) for more information.

### **Docker version :**

The docker version displays the installed versions of the Docker, Nothing more than that.

```plaintext
docker version
```

### **Docker search :**

"docker search" finds and displays relevant Docker images from registries, helping you discover and choose base containers for your applications.

```plaintext
docker search nginx
```

### **Docker pull :**

The "docker ps" command is valuable for efficiently checking the status and essential information of your active containers. It enables effective container monitoring and management, including tasks like identifying running containers, restarting or stopping specific containers, and inspecting their configurations.

To see the previously stopped containers use the option *“-a”*

```plaintext
sudo docker ps 
#you can user the command to get the images status
sudo docker ps -a
```

### **Docker run :**

Create and start a container from an image.

```plaintext
docker run <image>
```

To run a container in the background and regain control of the current terminal, use the "-d" option with the "docker run" command.

```plaintext
docker run -d <image_name>
```

To specify specific ports for Docker containers, use the "-p" option to map host ports to container ports, enabling communication between the host machine and the container.

```plaintext
docker run -p <host_port_number>:<container_port> <image_name>
```

To give the name to your container, use the option *“ — name”.*

```plaintext
docker run -p <host_port_number>:<container_port> <image_name> --name docker-image
```

### Docker stop :

Gracefully stop a running container.

```plaintext
 docker stop <container>
```

### Docker rm :

Remove one or more stopped containers.

```plaintext
docker rm <container>
```

### Docker images :

List available Docker images on your system.

```plaintext
 docker images
```

### Docker rmi :

It is used to remove one or more Docker images from your system. You need to stop the running container to delete the image.

```plaintext
docker rmi <image1> <image2> <image3>
or,
docker image prune -a
```

### Docker build :

Build a Docker image from a Docker file.

```plaintext
docker build <path/to/Dockerfile>
```

### Docker-compose up :

Start containers defined in a Docker Compose file.

```plaintext
docker-compose up
```

### Docker-compose down :

Stop and remove containers defined in a Docker Compose file.

```plaintext
docker-compose down
```

### Docker network ls :

List Docker networks on your system.

```plaintext
docker network ls
```

### Docker stats :

Display real-time resource usage statistics of running containers.

```plaintext
docker stats
```

### Docker Logs :

Display the logs of a specific container

```plaintext
docker logs <container>
```

And with that, we've covered the majority of the important commands in this post. If there are any commands I missed, feel free to mention them in the comments. That concludes our discussion for now. Happy Dockerizing!
