Kitloft

All tools / Docker Compose examples

MySQL with Docker Compose

MySQL with a named volume, root and app users, a health check and the port published only on localhost.

Customize names, versions and passwords →

compose.yaml
services:
  mysql:
    image: mysql:8.4
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: "change-me"
      MYSQL_DATABASE: "app"
      MYSQL_USER: "app"
      MYSQL_PASSWORD: "change-me"
    volumes:
      - mysql-data:/var/lib/mysql
    ports:
      - "127.0.0.1:3306:3306"
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1"]
      interval: 10s
      timeout: 5s
      retries: 10

volumes:
  mysql-data:

Passwords here are placeholders (change-me). The generator creates random ones for you.

How to use it

Commands
docker compose up -d
docker compose ps
docker compose logs -f

Prefer Kubernetes? See the MySQL Kubernetes version.