Docker Basics
1. Install Docker:
Task: Install Docker on your local machine (Linux, macOS, or Windows)
and verify the installation with docker --version .
Tooling: Docker Desktop or Docker Engine for your OS.
2. Run a Simple Docker Container:
Task: Run the official hello-world container to test your setup.
Command: docker run hello-world
3. Pull and Run an Nginx Container:
Task: Pull and run an Nginx container in detached mode ( -d ) and expose
it on port 8080.
Command: docker run -d -p 8080:80 nginx
4. List Running and Stopped Containers:
Task: Use Docker commands to list all running containers and stopped
containers.
Command: docker ps and docker ps -a
5. Inspect a Docker Container:
Task: Use docker inspect to get detailed information about a running
container (e.g., Nginx).
Command: docker inspect <container_id>
6. Stop and Remove a Docker Container:
Task: Stop and remove a running container.
Command: docker stop <container_id> and docker rm <container_id>
7. Run an Interactive Container (Ubuntu):
Task: Run an interactive Ubuntu container and access its terminal.
Command: docker run -it ubuntu /bin/bash
Working with Docker Images
8. Pull a Docker Image:
Task: Pull the official python Docker image from Docker Hub.
Command: docker pull python
9. Create a Dockerfile (Python App):
Task: Write a Dockerfile for a simple Python application and build an
image.
Commands: docker build -t my-python-app .
10. Run a Custom Docker Image:
Task: Run your custom Python application container from the image built
in the previous step.
Command: docker run my-python-app
11. Push an Image to Docker Hub:
Task: Tag your custom image and push it to Docker Hub (create a Docker
Hub account if needed).
Commands:
docker tag my-python-app <your-dockerhub-username>/my-python-app
docker push <your-dockerhub-username>/my-python-app
12. Use docker logs to Check Container Output:
Task: Run a container in detached mode and use docker logs to view its
output.
Command: docker logs <container_id>
13. Use Docker Volumes:
Task: Run an Nginx container with a volume mounted to persist data.
Command: docker run -d -p 8080:80 -v /path/on/host:/usr/share/nginx/html
nginx
14. Use Docker Bind Mounts:
Task: Use a bind mount to mount a file from your host to the container.
Command: docker run -d -p 8080:80 -v
/path/to/file.html:/usr/share/nginx/html/index.html nginx
15. Create a Multi-Stage Dockerfile:
Task: Create a multi-stage Dockerfile to optimize image size for a
simple Node.js app.
Learn to reduce image size by using multiple build stages.
Networking and Linking Containers
16. Inspect Docker Networks:
Task: Use docker network ls and docker network inspect to list and
inspect Docker networks.
Command: docker network ls , docker network inspect <network_name>
17. Run Containers on a Custom Network:
Task: Create a custom Docker bridge network and run two containers on
it.
Command:
docker network create my-custom-network
docker run -d --network my-custom-network --name nginx-container
nginx
docker run -d --network my-custom-network --name alpine-container
alpine
18. Link Two Containers (Nginx + Python App):
Task: Link an Nginx container to a Python app container by configuring
Nginx as a reverse proxy.
Use Docker networking to make the containers communicate.
19. Use Docker DNS to Communicate Between Containers:
Task: Set up two containers on the same Docker network and use DNS for
inter-container communication.
Example: Ping from one container to another using container names.
Docker Compose for Multi-Container Applications
20. Set Up a Docker Compose File:
Task: Write a docker-compose.yml file to run a multi-container setup
(e.g., Python app with Redis).
Command: docker-compose up
21. Run and Stop Docker Compose Services:
Task: Start and stop the services defined in your Docker Compose file.
Commands: docker-compose up -d and docker-compose down
22. Scale Docker Compose Services:
Task: Use Docker Compose to scale a service (e.g., run multiple
instances of your Python app).
Command: docker-compose up --scale web=3
23. Use Volumes in Docker Compose:
Task: Define and use volumes in Docker Compose to persist data for a
service like MySQL.
Modify the docker-compose.yml to include volumes for data persistence.
24. Add a Load Balancer with Docker Compose:
Task: Use Nginx as a load balancer to distribute traffic across multiple
instances of a web app in Docker Compose.
Learn load balancing basics with Nginx.
Docker Swarm and Orchestration
25. Initialize Docker Swarm:
Task: Set up Docker Swarm mode by initializing a swarm and adding a
worker node.
Command: docker swarm init
26. Deploy a Stack to Docker Swarm:
Task: Use Docker Compose with Docker Swarm to deploy a simple stack
(multi-container app).
Command: docker stack deploy -c docker-compose.yml my-stack
27. Scale Services in Docker Swarm:
Task: Scale a service running on Docker Swarm to multiple instances.
Command: docker service scale my-service=3
28. Monitor Docker Swarm Services:
Task: Use docker service ls and docker service ps to monitor the status
of services in the swarm.
Commands: docker service ls , docker service ps <service_name>
Advanced Docker Topics
29. Create a Custom Docker Network (Overlay Network):
Task: Create an overlay network in Docker Swarm for multi-host
networking.
Command: docker network create --driver overlay my-overlay-network
30. Integrate Docker with a CI/CD Pipeline (GitHub Actions):
Task: Set up a simple CI/CD pipeline using GitHub Actions to build and
push Docker images to Docker Hub.
Example: Trigger a Docker image build on every push to the GitHub
repository.