Docker is a powerful tool for containerizing applications. Here are the most common Docker commands to get you started quickly.
1. Check Docker Version
Check which Docker version is installed:
docker --version
2. List Docker Images
See all downloaded Docker images:
docker images
3. Pull an Image from Docker Hub
Download an image from Docker Hub:
docker pull <image_name>:<tag>
# Example:
docker pull nginx:latest
4. Run a Container
Run a container in detached mode with port mapping:
docker run -d -p <host_port>:<container_port> <image_name>
# Example:
docker run -d -p 8080:80 nginx
5. List Running Containers
See containers that are currently running:
docker ps
6. List All Containers
See all containers, including stopped ones:
docker ps -a
7. Stop a Running Container
Stop a container by ID or name:
docker stop <container_id_or_name>
8. Start a Stopped Container
Start a container by ID or name:
docker start <container_id_or_name>
9. Remove a Container
Delete a container by ID or name:
docker rm <container_id_or_name>
10. Remove an Image
Delete an image by name or ID:
docker rmi <image_name_or_id>
11. View Container Logs
Check logs of a running container:
docker logs <container_id_or_name>
12. Execute a Command Inside a Running Container
Access the shell of a container:
docker exec -it <container_id_or_name> /bin/bash
# Or use sh for Alpine-based containers
13. Build an Image from a Dockerfile
Build a custom Docker image:
docker build -t <image_name>:<tag> .
14. Tag an Image
Assign a new tag to an existing image:
docker tag <source_image> <target_image>
15. Push an Image to Docker Hub
Upload an image to Docker Hub:
docker push <image_name>:<tag>
Bonus Tips
- Use
docker-composefor multi-container setups. - Clean up unused containers, images, and networks with:
docker system prune
Master these commands to become productive with Docker quickly! 🚀🐳
Top comments (0)