Docker: MySQL, MariaDB, PostgreSQL

docker-compose.yml

version: '3.4'

services:
  mysql:
    image: mysql:latest
    container_name: mysql
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: test_db
      MYSQL_USER: test
      MYSQL_PASSWORD: test
    ports:
      - 3306:3306
    volumes:
      - mysql_db_data_container:/var/lib/mysql:rw
      - ${PWD}/docker/mysql/initdb_sql_scripts:/docker-entrypoint-initdb.d/:ro
      - ${PWD}/docker/mysql/mysql.conf:/etc/mysql/conf.d
    healthcheck:
      test: "/usr/bin/mysql --user=root --password=password --execute \"SHOW DATABASES;\""
      interval: 2s
      timeout: 20s
      retries: 10

  mariadb:
    image: mariadb:latest
    container_name: mariadb
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: test_db
      MYSQL_USER: test
      MYSQL_PASSWORD: test
    ports:
      - 3307:3306
    volumes:
      - mariadb_data_container:/var/lib/mysql:rw
      - ${PWD}/docker/mariadb/initdb_sql_scripts:/docker-entrypoint-initdb.d/:ro
      - ${PWD}/docker/mariadb/mariadb.conf:/etc/mysql/conf.d

  postgres:
    image: postgres:latest
    container_name: postgres
    restart: always
    environment:
      POSTGRES_DB: test_db
      POSTGRES_USER: test
      POSTGRES_PASSWORD: test
    ports:
      - 5432:5432
    volumes:
      - postgres_db_data_container:/var/lib/postgresql/data:rw
      - ${PWD}/docker/postgres/initdb_sql_scripts:/docker-entrypoint-initdb.d:ro
      - ${PWD}/docker/postgres/postgres.conf:/etc/postgresql/postgresql.conf

volumes:
  mysql_db_data_container:
  mariadb_data_container:
  postgres_db_data_container:
Continue reading

LoopBack 3 – Simple API with Oracle Example

Expose your Oracle Database as a REST service with LoopBack 3 (Node.js Open API Framework)

This post is continuation of previous post. So if you want to start from beginning, read that one as well.

Follow this link to create a Oracle container 🙂

You can find LoopBack 3 project in the following repository. After clonning switch to oracle branch 🙂 or run the following command.

git checkout oracle

https://github.com/kenanhancer/loopback3-simple-api.git

Oracle Docker Container Exercise

You can up and run Oracle Docker container in your local machine and later connect from sqlplus CLI to query your database.

Follow the following Oracle GitHub link for more details

https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance

After cloning Oracle docker-images repository from GitHub, run the following command in your terminal to build a Oracle Docker XE image.

docker build --force-rm=true --no-cache=true --shm-size=1G --build-arg DB_EDITION=xe -t oracle/database:18.4.0-xe -f Dockerfile.xe .

When build is done, run the following command to start a Oracle XE Database container.

docker run -d --name oracleXe --network=oracle_xe_network -p 1521:1521 -p 5500:5500 -e ORACLE_PWD="Pass_123456" oracle/database:18.4.0-xe

LoopBack 3 – Simple API with MySQL Example

Expose your MySQL Database as a REST service with LoopBack 3 (Node.js Open API Framework)

This post is continuation of previous post. So if you want to start from beginning, read that one as well.

Follow this link to create a MySQL container 🙂

Node.js MySQL example will not start wihout running the following code in MySQL Database container. So, run the following command in terminal. If your Node.js app still doesn't connect, then try other options.

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'your_root_password';
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_root_password';

Run the following script for normal user.

ALTER USER 'foo'@'%' IDENTIFIED WITH mysql_native_password BY 'your_foo_password';
ALTER USER 'foo'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_foo_password';

Then run the following script

FLUSH PRIVILEGES;

You can find LoopBack 3 project in the following repository. After clonning switch to mysql branch 🙂 or run the following command.

git checkout mysql

https://github.com/kenanhancer/loopback3-simple-api.git

MySQL Docker Container Exercise

You can up and run MySQL Docker container in your local machine and later connect from mysql CLI to query your database.

Run the following command in your terminal to up and run a MySQL Database Docker container.

docker run -p 3306:3306 --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:latest

Run the below code in the terminal to connect to running container.

docker exec -it some-mysql bash

Run the below code in the terminal after connecting to container.

mysql -h 127.0.0.1 -P 3306 -u root -p

Then you need to enter password, we need to enter my-secret-pw

Follow the following link for more details

https://hub.docker.com/_/mysql

There are more practice in this video 🙂