2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Docker]ローカル開発用MySQL

Posted at

概要

ローカル開発で使用してMySQLサーバを立てたい場合に、Dockerで簡単にMySQLサーバを起動する方法です。
また、今回のサンプルはデータをローカルのストレージに永続化します。
サンプル

手順

MySQLの使用するDockerイメージの取得

以下のコマンドにて使用するMySQLのDockerイメージを取得します。<version>は使用するMySQLのバージョンです。MySQLバージョン

docker pull mysql:<version>

docker-compose.yml作成

docker-composeファイルを作成します。必要に応じて各項目を変更してください。

version: '3'
services:
  mysql:
    container_name: dev-mysql
    image: mysql:<version>
    ports:
      - 3306:3306
    volumes:
      - <local_storage>:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=<passwrod>
      - MYSQL_DATABASE=<database>
項目 内容
version 取得したMySQLのバージョン
local_storage データを保存するローカルパス
passwrod ルートパスワード
database データベース名

起動

docker-compose up -d

停止

docker-compose stop

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?