Top 10 Docker Commands Every Developer Should Know
Juan Soares
Fullstack Software Engineer | React | NodeJS | TypeScript | JavaScript | AWS | DevOps | TDD | 3x AWS Certified
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.
Senior Software Engineer | Full Stack Developer | C# | .NET | .NET Core | React | Amazon Web Service (AWS)
2 个月Very informative. Thanks for sharing! ??
.NET Developer | C# | TDD | Angular | Azure | SQL
2 个月Great advice
Senior Mobile Developer | Android Software Engineer | Jetpack Compose | GraphQL | Kotlin | Java | React Native
2 个月Great article!
Senior Software Engineer | Backend-Focused Fullstack Developer | .NET | C# | Angular | React.js | TypeScript | JavaScript | Azure | SQL Server
2 个月Thanks for sharing Juan Soares