DEV Community

Cover image for Basic Docker Commands CheatSheet
Sarvesh Mishra
Sarvesh Mishra

Posted on • Originally published at sarvesh.xyz

Basic Docker Commands CheatSheet

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.

Docker Basics

1. Check Docker Version

To verify that Docker is installed and see its version:

docker --version
Enter fullscreen mode Exit fullscreen mode

2. Display Docker Info

For detailed information about your Docker installation:

docker info
Enter fullscreen mode Exit fullscreen mode

3. List Running Containers

To see the list of running containers:

docker ps
Enter fullscreen mode Exit fullscreen mode

4. List All Containers

To see all containers, including stopped ones:

docker ps -a
Enter fullscreen mode Exit fullscreen mode

5. Pull Docker Image

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

docker pull <image_name>
Enter fullscreen mode Exit fullscreen mode

6. Search for Docker Images

To search for Docker images on Docker Hub:

docker search <image_name>
Enter fullscreen mode Exit fullscreen mode

7. Run a Docker Container

To start a container based on an image:

docker run <image_name>
Enter fullscreen mode Exit fullscreen mode

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

8. Stop a Running Container

To stop a running container gracefully:

docker stop <container_id>
Enter fullscreen mode Exit fullscreen mode

9. Remove a Container

To remove a stopped container:

docker rm <container_id>
Enter fullscreen mode Exit fullscreen mode

10. Remove an Image

To remove a Docker image:

docker rmi <image_name>
Enter fullscreen mode Exit fullscreen mode

11. List Docker Images

To list all locally available Docker images:

docker images
Enter fullscreen mode Exit fullscreen mode

12. Display Container Logs

To view the logs of a running container:

docker logs <container_id>
Enter fullscreen mode Exit fullscreen mode

13. Execute Commands Inside a Container

To run a command inside a running container:

docker exec -it <container_id> <command>
Enter fullscreen mode Exit fullscreen mode

14. Copy Files To/From a Container

To copy files to/from a container:

docker cp <file> <container_id>:<destination_path>
Enter fullscreen mode Exit fullscreen mode

15. Inspect Container/Network/Volume

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

docker inspect <container_id>/<network_name>/<volume_name>
Enter fullscreen mode Exit fullscreen mode

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.


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.

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

Top comments (0)