Getting Started with Docker
docker containers devops
Docker
Docker is a technology to run containerized applications. Containers package your application with all its dependencies, ensuring it runs the same everywhere.
Essential Commands
View Running Containers
docker ps
To see all containers (including stopped ones):
docker ps -a
Stop Containers
Stop a specific container:
docker stop <container_id>
Stop all running containers:
docker stop $(docker ps -q)
Remove Containers
Remove a stopped container:
docker rm <container_id>
Remove all stopped containers:
docker container prune
View Images
docker images
Remove Images
docker rmi <image_id>
Remove all unused images:
docker image prune -a
Quick Tips
- Use
-dflag to run containers in detached (background) mode - Use
--rmto automatically remove the container when it stops - Use
-vto mount volumes for persistent data - Use
--nameto give containers memorable names
docker run -d --rm --name my-app -p 8080:80 nginx
This runs nginx in the background, maps port 8080 to container’s port 80, and removes the container automatically when stopped.