5  Week 2 (09-Oct-2025)


5.1 Docker Introductory Exercises

5.1.1 1. Install Docker

  • Exercise: Install Docker on your local machine.
  • Solution: Follow the official installation instructions for your operating system:
    • Windows & macOS: Use Docker Desktop - Docker Installation Guide

    • Linux: Use apt, yum, or dnf to install Docker.

      sudo apt-get update
      sudo apt-get install docker-ce docker-ce-cli containerd.io
  • Verification: Run the command:
     docker --version
  • Expected Output: Displays the installed Docker version.

5.1.2 2. Run Your First Container

  • Exercise: Run a simple container using the hello-world image.
  • Solution:
     docker run hello-world
  • Expected Output: A message indicating that Docker is successfully installed.

5.1.3 3. List Docker Images

  • Exercise: List all Docker images on your system.
  • Solution:
     docker images
  • Expected Output: A table listing all images, including hello-world.

5.1.4 4. Pull a Docker Image

  • Exercise: Pull the nginx image from Docker Hub.
  • Solution:
     docker pull nginx
  • Expected Output: Confirmation of the download and extraction of the nginx image.

5.1.5 5. Run a Web Server in a Container

  • Exercise: Run the nginx container and map port 80 on the container to port 8080 on the host.
  • Solution:
     docker run -d -p 8080:80 nginx
  • Expected Output: A unique container ID indicating that the container is running.
  • Verification: Open http://localhost:8080 in a web browser to see the default Nginx page.

5.1.6 6. List Running Containers

  • Exercise: List all running containers.
  • Solution:
     docker ps
  • Expected Output: A table listing the running nginx container.

5.1.7 7. Stop a Running Container

  • Exercise: Stop the running nginx container.
  • Solution:
     docker stop <container_id>
  • Note: Replace <container_id> with the actual ID from the docker ps command.
  • Expected Output: The container ID indicating it was stopped successfully.

5.1.8 8. Remove a Container

  • Exercise: Remove the stopped nginx container.
  • Solution:
     docker rm <container_id>
  • Note: Replace <container_id> with the actual ID of the container.
  • Expected Output: The container ID indicating it was removed.

These exercises introduce basic Docker concepts, from running containers to creating images and using volumes. Completing them will give you a solid foundation in Docker usage.