Complete Docker Tutorial with GUI Examples (Docker Desktop Focused)
1. What is Docker?
Docker is an open-source platform that uses OS-level virtualization to deliver software in packages called **containers**. Containers are lightweight, standalone, executable packages of software that include everything needed to run an application: code, runtime, system tools, system libraries, and settings.
The primary benefit of Docker is its ability to provide a consistent environment across different computing environments (development, testing, production). This helps eliminate "it works on my machine" problems and streamlines the entire software development lifecycle.
Key Docker Concepts:
- Containerization: The technology of packaging applications and their dependencies into isolated units (containers).
- Images: Read-only templates used to create containers. Images are built from a set of instructions in a `Dockerfile`. Think of an image as a blueprint or a class.
- Containers: Runnable instances of Docker images. A container is a lightweight, isolated execution environment that shares the host OS kernel but has its own isolated filesystem, process space, and network interface. Think of a container as an object or a running process.
- Dockerfile: A text file containing a set of instructions that Docker uses to build an image.
- Docker Engine: The core Docker runtime that builds and runs containers. It includes the Docker Daemon (the background service) and the Docker CLI (command-line interface).
- Docker Hub: A cloud-based registry service where you can find, store, and share public and private Docker images.
2. Docker Desktop Installation
Docker Desktop is an easy-to-install application for Windows, macOS, and Linux that provides a straightforward GUI to manage your containers, applications, and images directly from your machine. It includes the Docker Engine, Docker CLI, Docker Compose, Kubernetes (optional), and other helpful tools.
A. System Requirements:
- Windows: Windows 10 64-bit: Home or Pro version 21H2 or higher, or Enterprise or Education version 21H2 or higher. WSL 2 backend required.
- macOS: macOS Ventura 13 or newer. Intel or Apple Silicon chip.
- Linux: Modern Linux distribution with kernel 5.10+ (Ubuntu, Debian, Fedora, Arch).
B. Installation Steps:
- Download Docker Desktop: Go to the official Docker Desktop download page: docs.docker.com/desktop/install/. Download the installer for your operating system.
- Run the Installer:
- Windows: Double-click the `.exe` installer. Follow the wizard. Ensure "Install required Windows components for WSL 2" (or "WSL 2 backend" is enabled). A restart might be required.
- macOS: Double-click the `.dmg` file and drag the Docker icon to your Applications folder. Open Docker from Applications.
- Linux: Follow distribution-specific instructions (e.g., download `.deb` or `.rpm` and install via package manager, then run `systemctl start docker`).
- Initial Setup & Login:
- After installation, launch Docker Desktop. It might take a moment to start the Docker Engine.
- You'll typically be prompted to log in to Docker Hub (optional, but recommended for pulling/pushing images).
- Docker Desktop will show a tutorial or a dashboard indicating it's running.
- Verify Installation (CLI): Open your terminal/command prompt and run:
docker --version
docker compose version
docker run hello-world # This pulls and runs a simple container to confirm functionality
3. Docker Desktop UI Overview
The Docker Desktop application provides a user-friendly graphical interface to manage various Docker components.
Access: Launch the Docker Desktop application from your applications menu (Windows Start Menu, macOS Applications folder, Linux App Launcher).
Key Sections of Docker Desktop GUI:
- Home: A quick overview, often with tutorials and recommended images.
- Containers: View and manage running and stopped containers. This is your most frequent stop.
- Images: View and manage Docker images stored locally.
- Volumes: Manage Docker volumes for persistent data.
- Networks: View and manage Docker networks.
- Dev Environments: (Newer feature) Manage isolated development environments.
- Extensions: Discover and install Docker extensions for added functionality.
- Settings (Gear Icon): Configure Docker Desktop's behavior, resources, Docker Engine, Kubernetes, etc.
- Troubleshoot (Bug Icon): Access diagnostic tools, reset Docker Desktop.
- Docker Hub (Whale Icon): Connects to your Docker Hub account.
4. Core Concepts Explained for GUI Users
Let's delve into the fundamental Docker concepts with a focus on how they appear and are managed in Docker Desktop.
A. Images (Blueprints)
An image is a read-only template with instructions for creating a Docker container. It packages the application code, a runtime (like Node.js or Python), libraries, environment variables, and configuration files.
- View in Docker Desktop: Go to the **Images** tab. You'll see a list of images you've pulled or built locally.
- Pulling Images (GUI):
- In the **Images** tab, click **Pull**.
- Enter the image name (e.g., `nginx:latest`, `ubuntu:22.04`).
- Click **Pull**. Docker Desktop will download the image from Docker Hub.
# Equivalent CLI:
docker pull nginx:latest
- Building Images (CLI - requires Dockerfile):
Images are built from a `Dockerfile`. Create a new folder (e.g., `my-web-app`), then create `Dockerfile` and `index.html` inside it.
# Dockerfile
FROM nginx:latest # Use the official Nginx image as base
COPY index.html /usr/share/nginx/html/ # Copy your HTML file into the Nginx web root
EXPOSE 80 # Inform Docker that the container listens on port 80
CMD ["nginx", "-g", "daemon off;"] # Command to run Nginx when container starts
# index.html
<!DOCTYPE html>
<html>
<head>
<title>My Docker Webpage</title>
</head>
<body>
<h1>Hello from Docker!</h1>
<p>This page is served by Nginx in a container.</p>
</body>
</html>
Open your terminal in the `my-web-app` directory and build:
docker build -t my-custom-nginx-app . # The '.' means build from Dockerfile in current directory
This newly built image will appear in the **Images** tab of Docker Desktop.
B. Containers (Running Instances)
A container is a running instance of an image. You can start, stop, pause, restart, and delete containers.
- View in Docker Desktop: Go to the **Containers** tab. This lists all your running and stopped containers.
- Creating/Running Containers (GUI):
- In the **Images** tab, hover over an image (e.g., `my-custom-nginx-app`).
- Click the **Run** button.
- A dialog will appear:
- Optional settings: You can define a **Container name** (e.g., `my-nginx-instance`).
- Ports: Map a **Host port** (e.g., `8080`) to the **Container port** (`80` for Nginx). This allows you to access the web server from your host machine at `http://localhost:8080`.
- Click **Run**. The container will start and appear in the **Containers** tab.
# Equivalent CLI:
docker run -d -p 8080:80 --name my-nginx-instance my-custom-nginx-app
# -d: run in detached mode (background)
# -p 8080:80: map host port 8080 to container port 80
# --name: assign a name to the container
You can now open your browser and navigate to `http://localhost:8080` to see your "Hello from Docker!" page.
5. Managing Containers (GUI)
The **Containers** tab in Docker Desktop provides a central place to control your running applications.
- List Containers: The main view shows:
- Name: The container's name.
- Status: `Running`, `Exited`, `Paused`.
- Ports: Mapped ports (e.g., `8080 > 80`).
- Image: The image the container was created from.
- Start/Stop/Restart/Pause/Delete:
- Hover over a container. Buttons for **Start**, **Stop**, **Restart**, **Pause**, **Delete** will appear.
- Click the corresponding button.
- Deleting a container removes its writable layer, but the image remains.
- View Details (Click on Container Name):
- Logs: View real-time logs from the container's standard output.
- Inspect: See detailed JSON configuration (network, volumes, environment variables).
- Stats: Monitor CPU, Memory, Disk I/O, Network I/O in real-time.
- Files: Browse the container's filesystem. (Very useful for debugging!).
- Terminal: Open a shell directly inside the running container (e.g., `/bin/bash` or `/bin/sh`).
# Equivalent CLI for terminal access:
docker exec -it my-nginx-instance bash # or sh
6. Managing Images (GUI)
The **Images** tab allows you to manage the templates for your containers.
- List Images: Shows downloaded and built images with their size, creation date, and tags.
- Run Image: Click the **Run** button next to an image to create a new container from it.
- Delete Image: Select an image and click the **Delete** (trash can) icon.
- You cannot delete an image if it's currently used by a running or stopped container. You must delete the container first.
# Equivalent CLI:
docker rmi my-custom-nginx-app # Removes the image
- Build Image: (As seen in section 4A, this is typically done via CLI using a `Dockerfile`).
- Push Image: Push your local image to Docker Hub (after logging in).
# Equivalent CLI:
docker push your_dockerhub_username/my-custom-nginx-app:latest
7. Managing Volumes (GUI)
Volumes are the preferred mechanism for persisting data generated by and used by Docker containers. They allow data to outlive the container's lifecycle.
8. Managing Networks (GUI)
Docker networks allow containers to communicate with each other and with the host machine. By default, Docker creates a `bridge` network.
9. Docker Compose (GUI & CLI)
Docker Compose is a tool for defining and running multi-container Docker applications. You define your application's services, networks, and volumes in a `compose.yaml` (or `docker-compose.yml`) file, then use a single command to bring up the entire application stack.
Docker Desktop integrates Docker Compose, allowing you to manage Compose-defined applications from the UI.
A. Example `compose.yaml` (Simple Web App with Database):
Create a directory (e.g., `my-compose-app`) and place the following files:
# compose.yaml
version: '3.8' # Specify Compose file format version
services:
web:
build: . # Build Dockerfile in current directory for this service
ports:
- "8000:80" # Map host port 8000 to container port 80
volumes:
- ./nginx-html:/usr/share/nginx/html # Mount local 'nginx-html' dir to Nginx web root
depends_on:
- db # Ensure 'db' service starts before 'web'
networks:
- app-network
db:
image: postgres:15-alpine # Use a PostgreSQL image
environment:
POSTGRES_DB: mydatabase
POSTGRES_USER: myuser
POSTGRES_PASSWORD: mypassword
volumes:
- db_data:/var/lib/postgresql/data # Persistent volume for database data
networks:
- app-network
volumes: # Define named volumes for persistence
db_data:
networks: # Define custom bridge network
app-network:
driver: bridge
# nginx-html/index.html (create 'nginx-html' directory first, then this file inside it)
<!DOCTYPE html>
<html>
<head>
<title>Docker Compose App</title>
</head>
<body>
<h1>Hello from Docker Compose!</h1>
<p>This is a multi-service application.</p>
<p>Web service talks to a PostgreSQL database.</p>
</body>
</html>
# Dockerfile (for the 'web' service, create in 'my-compose-app' root)
FROM nginx:latest
COPY nginx-html/ /usr/share/nginx/html/ # Copy local html to container
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
B. Running Docker Compose (CLI - from `my-compose-app` directory):
docker compose up -d # Builds, creates, starts, and runs services in detached mode
You can then access the web app at `http://localhost:8000`.
C. Managing Docker Compose Applications (GUI):
- In Docker Desktop, go to the **Containers** tab.
- You'll see a section labeled **Compose** (often at the top or in a sub-tab).
- Your `my-compose-app` application will appear here, showing its services (`web`, `db`).
- You can click on the application name (`my-compose-app`) to:
- **View Logs:** See aggregated logs from all services in the application.
- **Open in Browser:** Directly open the mapped port (e.g., `http://localhost:8000`).
- **Stop/Restart/Delete:** Control the entire application stack with one click.
- **Build/Up/Down:** Buttons to re-build images, re-create services, or stop and remove the stack.
- Click on individual services (`web`, `db`) to view their specific logs, stats, files, or open a terminal.
D. Stopping and Cleaning Up Compose App (CLI):
docker compose down # Stops and removes containers, networks, and default volumes
# If you created named volumes (like 'db_data'), you might need to remove them explicitly:
docker volume rm my-compose-app_db_data # The volume name is usually prefixed with project name
10. Docker Hub & Registries (GUI)
Docker Hub is the world's largest container image registry. Docker Desktop integrates directly with it.
A. Connecting to Docker Hub:
- In Docker Desktop, click the **whale icon** (Docker Hub) in the left sidebar.
- You'll be prompted to log in or create an account.
B. Exploring Docker Hub (in Docker Desktop):
- Once logged in, you can browse **Official Images**, **Verified Publishers**, and your own **Repositories**.
- You can search for images directly from the Docker Desktop UI.
- For any image found, you can click **Pull** to download it to your local machine.
C. Managing Your Repositories (in Docker Desktop):
- Go to the **Images** tab.
- As seen in Section 6, you can **Push to Hub** any image you've built locally (after tagging it with your Docker Hub username).
- This makes your custom images accessible to others or your CI/CD pipelines.
11. Docker Extensions
Docker Extensions enhance Docker Desktop's functionality, providing new capabilities like security scanning, Kubernetes dashboards, cloud integrations, and more, all within the Docker Desktop UI.
Access: Click **Extensions** in the left sidebar of Docker Desktop.
- Discover: Browse available extensions.
- Install: Click "Install" for any extension.
- Manage: View, enable, disable, or uninstall installed extensions.
Popular examples include: Disk Usage, Resource Monitor, Vulnerability Scan (Snyk), Kubernetes Dashboard.
12. Docker Desktop Settings & Resources
The **Settings** menu (gear icon in the top right) allows extensive configuration.
- General: Start Docker Desktop on login, enable/disable WSL 2 integration (Windows).
- Resources:
- Advanced: Allocate CPU, memory, disk image size for the Docker Engine.
- WSL Integration (Windows): Control which WSL 2 distros Docker integrates with.
- Docker Engine: Configure Docker Daemon settings (e.g., registry mirrors, experimental features) via JSON.
- Kubernetes: Enable/disable the built-in Kubernetes cluster (if needed for local K8s development). Reset Kubernetes cluster.
- Updates: Manage Docker Desktop updates.
- Experimental Features: Enable/disable features under development.
- Backup & Restore: Export/import Docker Desktop settings and data.
13. Troubleshooting Docker Desktop
When things don't work as expected, Docker Desktop provides several diagnostic tools.
Access: Click the **Troubleshoot** icon (bug icon) in the top right of Docker Desktop.
- Restart Docker Desktop: Often resolves minor glitches.
- Check Status: See if Docker Engine is running.
- Diagnose & Feedback: Generate a diagnostic bundle that can be shared with Docker support.
- Clean / Purge data:
- **Clean / Purge data:** Removes all images, containers, volumes, and networks. Use as a last resort, as it deletes all your local Docker data.
- **Reset to factory defaults:** Resets all settings to their default values.
- Open logs: Access Docker Desktop's internal logs.
- CLI for Troubleshooting: Don't forget the power of the command line for deeper inspection:
docker ps -a # Show all containers (running and stopped)
docker images -a # Show all images
docker logs <container_name_or_id> # Get logs from a specific container
docker inspect <container_name_or_id> # Get detailed info about a container/image/volume/network
docker system prune # Remove stopped containers, unused networks, dangling images, build cache (frees disk space)
docker volume prune # Remove unused volumes
14. Best Practices with Docker Desktop
- Keep Docker Desktop Updated: Regularly update to benefit from new features, bug fixes, and security patches.
- Understand the Basics: Even with a GUI, a fundamental understanding of Docker Images, Containers, Volumes, and Networks is essential.
- Use `compose.yaml` for Multi-Service Apps: Always define your multi-container applications with Docker Compose for easier management and reproducibility.
- Use Volumes for Persistent Data: Never rely on the container's writable layer for data you need to keep. Use named volumes or bind mounts.
- Optimize Dockerfiles:
- Use a `.dockerignore` file.
- Minimize layers (chain `RUN` commands).
- Use multi-stage builds for smaller images.
- Use specific image tags (e.g., `node:18-alpine`) instead of `latest`.
- Resource Management: Configure Docker Desktop's allocated CPU, memory, and disk space in settings to match your development needs and host machine's capabilities.
- Security:
- Regularly scan images for vulnerabilities (using Docker Scout or extensions).
- Be cautious with exposing ports to `0.0.0.0`.
- Cleanup Regularly: Use `docker system prune` and `docker volume prune` to free up disk space from unused Docker objects.
Docker Desktop: Your Gateway to Containerization!
Docker Desktop simplifies the complex world of containerization, providing a powerful yet accessible platform for developers. By leveraging its intuitive GUI alongside the command line for deeper control, you can efficiently build, run, and manage containerized applications, streamlining your development workflow and ensuring consistency across environments. Happy containerizing!