Postgresql and Mysql Docker containers

DB, docker, mysql, postgresql

To quickly get an instance of PostgreSQL and MySQL up and running, use the following docker-compose setup:

Create a subdirectory to place the docker-compose.yml and optionally the data files for the DBs:

Windows

cd %USERPROFILE%
mkdir dbs\data\mysql
mkdir dbs\data\psql
cd dbs

Others

cd ~
mkdir -p dbs/data/mysql
mkdir -p dbs/data/psql
cd dbs

Add this docker-compose.yml to start with:

version: '3.1'
services:
  mysql:
    image: mysql
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password
    ports:
      - "3306:3306"
    expose:
      - "3306"
    volumes:
      - ./data/mysql:/var/lib/mysql
  postgresql:
    image: postgres
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=password
    ports:
      - "5432:5432"
    expose:
      - "5432"
    volumes:
      - ./data/psql:/var/lib/postgresql/data

To bring them up:

docker-compose up

By default:

  • The PostgreSQL instance uses postgres / password as the admin.
  • The MySQL instance uses root / password for the admin.