Skip to content

Instantly share code, notes, and snippets.

@AlanD20
Last active August 8, 2023 15:24
Show Gist options
  • Save AlanD20/7ecacada8ed09927215ff40d88ec3262 to your computer and use it in GitHub Desktop.
Save AlanD20/7ecacada8ed09927215ff40d88ec3262 to your computer and use it in GitHub Desktop.
Docker Database Setup

Docker Database Setup

This is a simple project that helps you setup a simple MySQL, phpMyAdmin, Mailpit/Mailhog containers in a single docker compose file. The project contains a docker-compose file with a package.json to run the docker-compose commands easily.

{
"name": "db",
"version": "1.0.0",
"license": "MIT",
"scripts": {
"start": "docker-compose -f server.yml start",
"stop": "docker-compose -f server.yml stop",
"up": "docker-compose -f server.yml up -d",
"down": "docker-compose -f server.yml down"
}
}
version: "3.8"
name: dev
services:
# Database service
db:
image: mysql
ports:
- "3306:3306"
restart: always
# networks:
# - webnet
command: "--authentication_policy=mysql_native_password"
environment:
MYSQL_DATABASE: mydb
# MYSQL_ROOT_PASSWORD: password
MYSQL_ALLOW_EMPTY_PASSWORD: true
healthcheck:
retries: 10
test: [ "CMD", "mysqladmin", "ping", "-h", "localhost" ]
timeout: 20s
volumes:
- ./db-data:/var/lib/mysql
# ======================
# Email Testing Server
mailpit:
image: axllent/mailpit
# networks:
# - webnet
ports:
- "1025:1025"
- "8225:8025"
environment:
MP_DATA_FILE: /home
volumes:
- ./mailpit:/home
restart: unless-stopped
# ======================
# Email Testing Server
# mailhog:
# image: mailhog/mailhog:latest
# networks:
# - webnet
# ports:
# - "1025:1025"
# - "8225:8025"
# restart: on-failure
# ======================
# PhpMyAdmin to manage database with UI
phpmyadmin:
depends_on:
- db
# Save your eyes with this lightweight image, or enable the official one
image: beeyev/phpmyadmin-lightweight:latest
# image: phpmyadmin
tty: true
# networks:
# - webnet
ports:
- "8080:80"
restart: unless-stopped
environment:
- TZ=CET
- PMA_HOST=mysql
- PMA_USER=root
- PMA_HOST=db
# Enable network for Windows
# Linux does't need separate network
# ==========================
# networks:
# webnet:
# driver: bridge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment