[Docker]Using MySQL with Docker

File Preparation

Docker
└ docker-mysql
  └Docker-Compose.yml
  └ mysql
    ├ Dockerfile
    ├ my.cnf
    └ DB
      └world.sql

Docker-Compose.yml

version: "3.7"
services:
  mysql:
    build: ./mysql/    
    volumes:
      - ./mysql/db:/docker-entrypoint-initdb.d 
    image: original_mysql_world 
    platform: linux/amd64  # M1Mac
    environment:
      - MYSQL_ROOT_PASSWORD=root   

Reference http://docs.docker.jp/get-started/08_using_compose.html?highlight=mysql

Dockerfile

FROM mysql

EXPOSE 3306

ADD ./my.cnf /etc/mysql/conf.d/my.cnf

CMD ["mysqld"]

my.cnf

[mysqld]
character-set-server=utf8

[mysql]
default-character-set=utf8

[client]
default-character-set=utf8

world.sql

-- MySQL dump 10.13  Distrib 5.1.51, for pc-linux-gnu (i686)
--
-- Host: 127.0.0.1    Database: world
-- ------------------------------------------------------
-- Server version       5.1.51-debug-log

構築・起動

$ Docker-Compose build

$ Docker-Compose up -d

$ docker ps

$ docker exec -it <NAME> bash -p

$ mysql -u root -p -h 127.0.0.1

$ docker-compose down

$ docker-compose down --volumes

Docker

Posted by Next-k