Top 10 Docker Commands Every Developer Should Know

Top 10 Docker Commands Every Developer Should Know

Docker has revolutionized how we build, share, and deploy applications. Whether you're managing containers locally or orchestrating them in the cloud, mastering key Docker commands is essential for efficient development workflows.

In this article, I’ll highlight the top 10 Docker commands every developer should know, complete with practical use cases to level up your containerization skills.


1. docker pull

Usage:

docker pull <image-name>        

What It Does: Downloads a Docker image from a registry like Docker Hub.

Example:

docker pull node:16        

Quickly get the Node.js environment you need for development.


2. docker build

Usage:

docker build -t <image-name>:<tag> .
        

What It Does: Builds a Docker image from a Dockerfile and context.

Example:

docker build -t my-react-app:latest .        

Creates a custom image for your React app.


3. docker run

Usage:

docker run -d -p <host-port>:<container-port> <image-name>        

What It Does: Starts a new container from an image.

Example:

docker run -d -p 3000:3000 node:16        

Runs a Node.js app and maps port 3000 from the container to your local machine.


4. docker ps

Usage:

docker ps        

What It Does: Lists running containers, showing details like container ID, name, and ports.


5. docker stop

Usage:

docker stop <container-id>        

What It Does: Stops a running container.

Example:

docker stop 123abc        

Gracefully shuts down the container with ID 123abc.


6. docker rm

Usage:

docker rm <container-id>        

What It Does: Removes a stopped container.


7. docker rmi

Usage:

docker rmi <image-id>        

What It Does: Removes an unused Docker image to free up space.

Example:

docker rmi my-react-app:latest        

8. docker exec

Usage:

docker exec -it <container-id> <command>        

What It Does: Executes a command in a running container.

Example:

docker exec -it 123abc bash        

Access the shell of a running container for debugging.


9. docker logs

Usage:

docker logs <container-id>        

What It Does: Shows logs for a running or stopped container.

Example:

docker logs 123abc        

View your app's output and debug issues.


10. docker-compose up

Usage:

docker-compose up        

What It Does: Starts multiple containers as defined in a docker-compose.yml file.

Example:

docker-compose up -d        

Runs your multi-container app (e.g., a Node.js backend with a MongoDB database).


Conclusion

Mastering these Docker commands will significantly enhance your efficiency in developing, testing, and deploying containerized applications. From spinning up containers to debugging and managing images, these tools are the building blocks for modern development workflows.


Thank you so much for reading, if you want to see more articles you can click here, feel free to reach out, I would love to exchange experiences and knowledge.

Leandro Veiga

Senior Software Engineer | Full Stack Developer | C# | .NET | .NET Core | React | Amazon Web Service (AWS)

2 个月

Very informative. Thanks for sharing! ??

回复
Lucas Wolff

.NET Developer | C# | TDD | Angular | Azure | SQL

2 个月

Great advice

回复
Thiago Nunes Monteiro

Senior Mobile Developer | Android Software Engineer | Jetpack Compose | GraphQL | Kotlin | Java | React Native

2 个月

Great article!

回复
Alexandre Germano Souza de Andrade

Senior Software Engineer | Backend-Focused Fullstack Developer | .NET | C# | Angular | React.js | TypeScript | JavaScript | Azure | SQL Server

2 个月

Thanks for sharing Juan Soares

回复

要查看或添加评论,请登录

Juan Soares的更多文章

社区洞察

其他会员也浏览了