Basic Docker Commands CheatSheet
Tags: docker, kubernetes, systemdesign, softwaredevelopment
Published: 2023-09-16 08:43:37


Docker has become an indispensable tool in the world of software development and deployment. It enables developers to create, deploy, and run applications in lightweight, portable containers. Whether you're a seasoned Docker user or just getting started, having a cheat sheet of basic Docker commands can be incredibly helpful. In this guide, we'll provide you with a handy Docker command cheat sheet to keep at your fingertips.

## Prerequisites

Before you dive into Docker commands, make sure you have Docker installed on your system. You can download and install Docker from the [official Docker website](https://www.docker.com/get-started).

## Docker Basics

#### 1. Check Docker Version

To verify that Docker is installed and see its version:

```bash
docker --version
```

#### 2. Display Docker Info

For detailed information about your Docker installation:

```bash
docker info
```

#### 3. List Running Containers

To see the list of running containers:

```bash
docker ps
```

#### 4. List All Containers

To see all containers, including stopped ones:

```bash
docker ps -a
```

#### 5. Pull Docker Image

To download a Docker image from a registry (e.g., Docker Hub):

```bash
docker pull <image_name>
```

#### 6. Search for Docker Images

To search for Docker images on Docker Hub:

```bash
docker search <image_name>
```

#### 7. Run a Docker Container

To start a container based on an image:

```bash
docker run <image_name>
```

Add the -d flag to run the container in detached mode.

#### 8. Stop a Running Container

To stop a running container gracefully:

```bash
docker stop <container_id>
```

#### 9. Remove a Container

To remove a stopped container:

```bash
docker rm <container_id>
```

#### 10. Remove an Image

To remove a Docker image:

```bash
docker rmi <image_name>
```

#### 11. List Docker Images

To list all locally available Docker images:

```bash
docker images
```

#### 12. Display Container Logs

To view the logs of a running container:

```bash
docker logs <container_id>
```

#### 13. Execute Commands Inside a Container

To run a command inside a running container:

```bash
docker exec -it <container_id> <command>
```

#### 14. Copy Files To/From a Container

To copy files to/from a container:

```bash
docker cp <file> <container_id>:<destination_path>
```

#### 15. Inspect Container/Network/Volume

To view detailed information about a container/network/volume:

```bash
docker inspect <container_id>/<network_name>/<volume_name>
```

#### Conclusion

>This Docker command cheat sheet provides a quick reference to essential Docker commands that every developer should be familiar with. Docker simplifies the process of building, deploying, and scaling applications, making it a valuable tool for modern software development.

<Notice type="note">
Remember that this is just the tip of the iceberg when it comes to Docker's capabilities. As you become more experienced with Docker, you'll discover many more advanced commands and features to enhance your containerization workflow. Docker's official documentation is a fantastic resource to explore those advanced topics further.
</Notice>

##### Happy Dockerizing! 🐋 See you in next post. Don't forget to comment your thoughts for this post. Share knowledge with others...