Basic Docker Commands CheatSheet

Basic Docker Commands CheatSheet

ยท

3 min read

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

2. Display Docker Info

For detailed information about your Docker installation:

docker info

3. List Running Containers

To see the list of running containers:

docker ps

4. List All Containers

To see all containers, including stopped ones:

docker ps -a

5. Pull Docker Image

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

docker pull <image_name>

6. Search for Docker Images

To search for Docker images on Docker Hub:

docker search <image_name>

7. Run a Docker Container

To start a container based on an image:

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:

docker stop <container_id>

9. Remove a Container

To remove a stopped container:

docker rm <container_id>

10. Remove an Image

To remove a Docker image:

docker rmi <image_name>

11. List Docker Images

To list all locally available Docker images:

docker images

12. Display Container Logs

To view the logs of a running container:

docker logs <container_id>

13. Execute Commands Inside a Container

To run a command inside a running container:

docker exec -it <container_id> <command>

14. Copy Files To/From a Container

To copy files to/from a container:

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

15. Inspect Container/Network/Volume

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

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.

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