🎯 Docker Compose Quiz

Fill in the missing parts of this Docker Compose configuration. Test your knowledge!

The gray dashed boxes represent missing values that you need to figure out.

🔍 Docker Compose Configuration Quiz:

version: '___'
services:
  db:
    image: mysql:___
    container_name: ________
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: ____
      MYSQL_DATABASE: ______
      MYSQL_USER: ____
      MYSQL_PASSWORD: ________
    ports:
      - "____:____"
    volumes:
      - _________________________
    networks:
      app_net:
        ipv4_address: ___________

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: phpmyadmin
    restart: always
    environment:
      PMA_HOST: __
      PMA_AUTH_TYPE: cookie
    ports:
      - "____:__"
    depends_on:
      - db
    networks:
      app_net:
        ipv4_address: 172.20.0.3

networks:
  app_net:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: 172.20.0.0/16

📋 Configuration Overview

Docker Compose Version

version: '___' - This is a stable version that supports most modern Docker features. This version was released with Docker 19.03.0+.

🗄️ Database Service (MySQL)

Image & Container

mysql:___ - Uses MySQL version 8.0, which includes improved performance, JSON support, and better security features.

container_name: ________ - Custom name makes it easier to reference and manage.

⚠️ Security Concerns

MYSQL_ROOT_PASSWORD: ____ - Using weak passwords as the root password is highly insecure for production environments.

MYSQL_PASSWORD: ________ - Weak passwords should be avoided. Consider using environment variables or secrets.

Volume Mapping

_________________________ - Data persists even when container is removed. The local data folder will be created in your project directory.

Port Mapping

"____:____" - MySQL's default port (3306). Left side is host port, right side is container port.

🌐 phpMyAdmin Service

Database Connection

PMA_HOST: __ - Connects to the MySQL service using the service name as hostname.

PMA_AUTH_TYPE: cookie - Uses cookie-based authentication (recommended for web interface).

Service Dependencies

depends_on: - __ - Ensures the database starts before phpMyAdmin, but doesn't wait for MySQL to be fully ready.

Web Access

"____:__" - Access phpMyAdmin at http://localhost:8080

🔗 Network Configuration

Custom Network

app_net - Creates an isolated network for your services.

subnet: 172.20.0.0/16 - Defines the IP range for the network.

Static IP Addresses

Database: ___________

phpMyAdmin: 172.20.0.3

Note: Static IPs are usually not necessary unless you have specific networking requirements.

🚀 Usage Instructions

Starting the Services

Run: docker-compose up -d

The -d flag runs containers in the background.

Accessing phpMyAdmin

1. Open browser and go to http://localhost:8080

2. Login with:

  • Server: __
  • Username: ____ or ____
  • Password: ________ or ____

Stopping the Services

Run: docker-compose down

Add -v flag to also remove volumes (this will delete your data!).

💡 Suggested Improvements

1. Use Environment Files: Create a .env file for passwords and sensitive data.
2. Add Health Checks: Implement health checks to ensure services are ready before dependent services start.
3. Remove Static IPs: Unless specifically needed, let Docker handle IP assignment automatically.
4. Use Strong Passwords: Generate secure passwords and store them in environment variables.
5. Add Resource Limits: Set memory and CPU limits to prevent resource exhaustion.