docker --version5 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, ordnfto install Docker.sudo apt-get update sudo apt-get install docker-ce docker-ce-cli containerd.io
- Verification: Run the command:
- Expected Output: Displays the installed Docker version.
5.1.2 2. Run Your First Container
- Exercise: Run a simple container using the
hello-worldimage. - 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
nginximage from Docker Hub. - Solution:
docker pull nginx- Expected Output: Confirmation of the download and extraction of the
nginximage.
5.1.5 5. Run a Web Server in a Container
- Exercise: Run the
nginxcontainer 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:8080in 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
nginxcontainer.
5.1.7 7. Stop a Running Container
- Exercise: Stop the running
nginxcontainer. - Solution:
docker stop <container_id>- Note: Replace
<container_id>with the actual ID from thedocker pscommand. - Expected Output: The container ID indicating it was stopped successfully.
5.1.8 8. Remove a Container
- Exercise: Remove the stopped
nginxcontainer. - 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.