These exercises will help you apply the core Docker concepts and commands covered in the theory section. They focus on installing Docker, running basic containers, and mastering essential CLI commands.

Exercise 1: Install Docker

  • Follow the official installation guide for your operating system (Linux/macOS/Windows).
  • Verify your installation by running:

      docker --version
      docker info
    
  • Linux users: Ensure you can run Docker commands without sudo by adding your user to the docker group if needed.

Exercise 2: Run the hello-world Container

  • Run the simplest Docker container to verify your Docker setup:

      docker run hello-world
    
  • Observe the output and describe the steps Docker performs (image pull, container creation, execution).

Exercise 3: Explore Running Containers

  • Start an Nginx web server container in detached mode, mapping port 8080 on your host to port 80 in the container:

      docker run -d -p 8080:80 nginx
    
  • Check that the container is running with:

      docker ps
    
  • Open your web browser and navigate to http://localhost:8080 to see the Nginx welcome page.
  • Inspect the container logs using:

      docker logs <container_id>
    

Exercise 4: Interact with a Running Container

  • Access the running Nginx container’s shell:

      docker exec -it <container_id> sh
    
  • Explore the container’s filesystem, for example:

      ls /usr/share/nginx/html
    
  • Exit the container shell by typing exit.

Exercise 5: Manage Container Lifecycle

  • Stop the running Nginx container:

      docker stop <container_id>
    
  • Remove the stopped container:

      docker rm <container_id>
    
  • List all containers, including stopped ones:

      docker ps -a
    

Optional Challenge: Run an Alpine Container

  • Start an interactive Alpine Linux container:

      docker run -it alpine sh
    
  • Explore basic Linux commands inside the container.
  • Exit and remove the container after you finish.

Summary:

These exercises provide hands-on experience with Docker installation, container creation and management, and interaction with running containers — building a solid foundation for the rest of the course.