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.

Rails w/ MySQL (Windows 7-64)

mysql, programming, rails

Mainly notes on setting up the following (suitable for Dreamhost’s Rails setup):

  • Ruby 1.8.7-p374
  • Rails 3.0.3
  • Ruby devkit  (from http://rubyinstaller.org/downloads/)
  • MySQL Installer 5.6.17 Community Server 64-bit
  • mysql2 GEM ‘0.2.22’

Install Ruby 1.8.7 by going to: http://rubyinstaller.org/downloads/

Install Rails 3.0.3 by: gem install rails -v 3.0.3

Latest MySQL: http://dev.mysql.com/downloads/mysql/

mysql2 GEM:

  1. Get mysql-connector-c-6.1.3-win32.zip from http://dev.mysql.com/downloads/connector/c/. Unzip to C:devtools (or wherever).
  2. Run: gem install mysql2 -v '0.2.22' -- --with-mysql-dir="c:devtoolsmysql-connector-c-6.1.3-win32"  (Use whatever path you unzipped the connector above.)

Go to the Rails app and modify the GemFile:

...
gem 'mysql2', '0.2.22'
...

Run: bundle install

Copy c:devtoolsmysql-connector-c-6.1.3-win32liblibmysql.dll to %RUBY_HOME%bin