Docker Quickstart
Docker is an open-source platform that simplifies building, shipping, and running applications using containers. A container is a lightweight, portable unit that bundles an application with all its dependencies, ensuring it runs consistently across different environments.
Docker streamlines local development by offering isolated, consistent, and reproducible environments for applications and their dependencies. This helps eliminate common problems like environment mismatches and simplifies the setup process across different systems.
✅ Key Benefits
- Consistent environments – Eliminates "it works on my machine" issues by replicating the same setup everywhere.
- Isolated dependencies – Each project runs in its own container without interfering with others.
- Fast setup and teardown – Quickly start or stop environments using Docker commands or
docker-compose
. - Reproducible setups – Easily share and version your development environment with teammates.
- Supports multi-service apps – Run databases, APIs, and other services together locally.
- Great tooling support – Works well with IDEs, CI/CD pipelines, and testing tools.
- Lightweight and efficient – Containers are faster and use fewer resources than full virtual machines.
🚀 Docker Quickstart
1. Verify Docker is installed
docker --version
Make sure Docker Engine & CLI are properly set up.
2. Download an image
docker pull <image>:<tag>
Grabs an image (e.g., nginx:latest
) from Docker Hub or another registry.
3. Launch a container
docker run [OPTIONS] <image> [COMMAND] [ARGS…]
Creates and starts a container from the image.
Typical options include:
-d
: run detached-p host:container
: map ports--name <name>
: name your container
4. View running containers
docker ps # show active containers
docker ps -a # include stopped/exited ones
Helpful for tracking container status and IDs.
5. Execute a command inside a container
docker exec -it <container> <command>
Example: docker exec -it my_app bash
for an interactive shell.
6. Stop, restart, or kill
docker stop <container> # graceful shutdown
docker restart <container> # restart container
docker kill <container> # immediate force-stop
Use kill
only if stop
doesn’t respond.
7. Make a snapshot of changes
docker commit <container> <new-image>:<tag>
Captures container state into a new image.
8. Push images to a registry
docker login <registry> # authenticate
docker push <image>:<tag> # upload
Share your image via Docker Hub or private registries.
9. Clean up
docker rm <container> # remove container
docker rmi <image> # remove image
Options:
-f
: force removal-v
: remove attached volumes
✅ Summary Table
Step | Command Example |
---|---|
Check version | docker --version |
Pull image | docker pull ubuntu:latest |
Run container | docker run -d --name web -p 80:80 nginx |
List containers | docker ps -a |
Exec into container | docker exec -it web bash |
Stop container | docker stop web |
Commit changes | docker commit web web_snapshot:1.0 |
Push image | docker login → docker push web_snapshot:1.0 |
Cleanup | docker rm web → docker rmi web_snapshot:1.0 |
These commands cover the basic lifecycle: install → pull → run → interact → stop → save → share → clean. Once you're comfortable, you can explore more advanced features like building from Dockerfiles, managing networks/volumes, and orchestrating multi-container applications.