Skip to content

Instantly share code, notes, and snippets.

@kentlouisetonino
Last active December 21, 2023 01:52
Show Gist options
  • Save kentlouisetonino/1171b1d9dfc9f22f13eb774bdec2122d to your computer and use it in GitHub Desktop.
Save kentlouisetonino/1171b1d9dfc9f22f13eb774bdec2122d to your computer and use it in GitHub Desktop.
Description

Steps

Go to the root directory of the project. Create a new folder and file. After creating the file, put the sql content.

mkdir docker
cd docker
touch docker_mysql-init.sql
-- Put this inside the docker_mysql-init.sql.
CREATE DATABASE IF NOT EXISTS example-db;

Go back to the root directory of the project and create a new file. After creating the file put the yml content.

touch docker-compose.yml
version: '3.6'
services:
  example-db:
    image: mysql:8.0.28
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=example-db
    ports:
      - '3310:3310'
    volumes:
      - ./docker/docker_mysql_init.sql:/docker-entrypoint-initdb.d/docker_mysql_init.sql

Run the following commands below.

docker-compose up --build -d

Use a database client to connect to the project.

DB_HOST=127.0.0.1
DB_PORT=3310
DB_NAME=example-db
DB_USER=root
DB_ROOT_PASSWORD=root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment