Docker Challenges

Prepared by: Anwer Sadath Abdhul Muttaliff

Overview

This project demonstrates a series of Docker challenges designed to enhance your skills in containerization, image management, networking, and more. Each challenge includes step-by-step instructions and commands to help you master Docker.

Challenges

Challenge #1: Display Docker Help

Objective: Using the Docker client, display the help of the Docker management command container and the help of the run subcommand.

docker container --help
docker container run --help
Challenge #2: Search for MariaDB Image

Objective: Using the Docker CLI, search Docker Hub for an image called mariadb.

docker search mariadb
Challenge #3: Pull and List Docker Images

Objective: Pull the image called alpine with the edge tag and list all images downloaded locally.

docker pull alpine:edge
docker image ls
Challenge #4: Manage Containers and Files

Objective: Launch a container from the alpine:edge image, create a file inside it, and manage the container lifecycle.

Run the container:

docker container run -it --name myalpine alpine:edge

Create a new file in the container:

cd /root
touch a.txt
ls -ltr

Exit the container without stopping it:

Press Ctrl + P + Q

Check that the container is still running:

docker container ls

Re-attach to the container and verify the file:

docker container exec myalpine ls -ltr /root

Exit the container:

exit
Challenge #5: Run Nginx Web Server

Objective: Run the Nginx web server in a Docker container, access it via a browser, and check logs.

Run Nginx container:

docker container run -d -p 80:80 nginx

Access the server from a browser:

http://<your_host_IP>:80

Check the web server logs:

docker container logs <container_name>

Attach to the Nginx container:

docker container exec -it <nginx_container_id> sh
Challenge #6: Run Multiple Web Servers

Objective: Run two Nginx and two Apache containers with random ports, access them, and manage their lifecycle.

Run the containers:

docker container run -d -P nginx
docker container run -d -P nginx
docker container run -d -P httpd
docker container run -d -P httpd

Check the running containers and their ports:

docker container ls

Access the web servers from a browser using the displayed ports.

Stop the containers:

docker container stop <container_ID> ...

Remove all stopped containers:

docker container rm $(docker container ls -f status=exited -q)
Challenge #7: Install and Access SSH in Ubuntu

Objective: Run Ubuntu container, install and configure OpenSSH, and connect via SSH.

Run the Ubuntu container:

docker container run -it ubuntu:latest

Install OpenSSH server:

apt update && apt install ssh

Create a user and set its password:

useradd username
passwd username

Exit the container without stopping it:

Press Ctrl + P + Q

Check the IP address of the container:

docker inspect <container_ID> | grep -i ipaddress

Start the SSH service and connect to the container via SSH:

service ssh start
ssh username@<container_IP>
Challenge #8: Commit and Push Custom Image

Objective: Commit changes to a new image, start a container, and push the image to Docker Hub.

Commit the changes to a new image:

docker commit <container_ID> myubuntu:custom

Run a container from the new image:

docker container run -it myubuntu:custom /bin/bash

Push the image to Docker Hub:

docker login
docker tag myubuntu:custom <your_dockerhub_username>/myubuntu:custom
docker push <your_dockerhub_username>/myubuntu:custom
Docker Hub Push
Challenge #9: Build Custom Apache Image

Objective: Search for Apache image on Docker Hub, build a custom image from Dockerfile, and create a volume.

Search for Apache image:

docker search httpd

Download Dockerfile and httpd-foreground script:

Obtain from the GitHub repository linked in the Docker Hub description.

Build the custom image:

docker build -t <your_dockerhub_username>/myapache:latest .

Create and inspect a volume:

docker volume create webapp1
docker volume inspect webapp1

Copy files to the volume and start the Apache container:

docker container run -d -p 8080:80 -v webapp1:/usr/local/apache2/htdocs <your_dockerhub_username>/myapache:latest
Volume Webapp1
Challenge #10: Docker Networking Modes

Objective: Understand and use different Docker networking modes.

Bridge Network (Default):

docker run -d --name my-container my-image

Host Network:

docker run -d --network host my-image

None Network:

docker run -d --network none my-image

Container Network:

docker run -d --network container:<container_name_or_id> my-image

Overlay Network:

docker network create -d overlay my-overlay-network
docker service create --name my-service --network my-overlay-network my-image

Macvlan Network:

docker network create -d macvlan --subnet=192.168.1.0/24 --gateway=192.168.1.1 -o parent=eth0 my-macvlan-network
docker run -d --network my-macvlan-network my-image

Conclusion

These Docker challenges provide hands-on experience with containerization, image management, networking, and more. By completing these tasks, you'll gain a deeper understanding of Docker and its capabilities.

Back to Top Back to Home