Docker Task
Docker Task
1. Install Docker:
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
Task: Use Docker commands to list all running containers and stopped
containers.
Command: docker ps and docker ps -a
Task: Pull the official python Docker image from Docker Hub.
Command: docker pull python
Task: Run your custom Python application container from the image built
in the previous step.
Command: docker run my-python-app
Task: Run a container in detached mode and use docker logs to view its
output.
Command: docker logs <container_id>
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
Task: Use docker network ls and docker network inspect to list and
inspect Docker networks.
Command: docker network ls , docker network inspect <network_name>
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
Task: Start and stop the services defined in your Docker Compose file.
Commands: docker-compose up -d and docker-compose down
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.
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
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: 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.