A simplified reference for getting started with Docker: from installation, pulling images, running containers, and publishing to Docker Hub.
Install Docker from the official site:
👉 https://docs.docker.com/get-docker/
Verify installation:
docker --version
docker infodocker pull <image_name> # Download image from Docker Hub
docker images # List all downloaded imagesExample:
docker pull hello-worlddocker run <image_name> # Runs a new container
docker run -it <image_name> # Runs interactivelyEach run creates a new container with a random ID and name.
docker ps # Show running containers
docker ps -a # Show all containers (running + stopped)docker start <container_id|name> # Start a container
docker stop <container_id|name> # Stop a container
docker rename old_name new_name # Rename a container
docker rm <container_id|name> # Remove a stopped container
docker container prune # Remove all stopped containersdocker exec -it <container_id|name> <command> # Run command inside container
docker exec -it my_container node # Start Node.js shell
docker exec -it my_container /bin/bash # Access Linux shelldocker cp ./example.txt <container_name>:/example.txtdocker cp <container_name>:/example.txt ./copied.txtUse
cat <filename>inside the container to view file contents.
FROM alpine:latest
CMD ["echo", "Hello, Docker"]docker build -t my_custom_image .docker volume create my_volume
docker run -v my_volume:/data alpine
docker volume lsVolumes allow data to persist even after a container is deleted.
Create a docker-compose.yml file:
version: '3'
services:
web:
image: nginx
ports:
- "80:80"Start with:
docker-compose upStop with:
docker-compose downCreate a .dockerignore file to exclude files/folders from the image:
node_modules
*.log
Dockerfile
- Login:
docker login- Tag the image:
docker tag my_image <username>/<repository>:latest- Push the image:
docker push <username>/<repository>:latest- Pull from anywhere:
docker pull <username>/<repository>:latestA Docker registry is a system for storing and distributing Docker images.
- Docker Hub is the default public registry.
- Run your own private registry:
docker run -d -p 5000:5000 --name registry registry:2- Use lightweight base images (like
alpine) - Use multi-stage builds for production apps
- Clean up unused packages in Dockerfile
- Tag images clearly (e.g.,
:v1,:latest,:prod) - Use
.dockerignoreto reduce image size and build time
| Action | Command |
|---|---|
| List Images | docker images |
| Run Container | docker run <image> |
| List Containers | docker ps -a |
| Build Image | docker build -t name . |
| Exec into Container | docker exec -it <id> bash |
| Copy Files | docker cp |
| Push to Docker Hub | docker push |