20160104 my sql_with_docker

11
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | MySQL on Docker Created: 2016/01/04 Updated: 2016/01/05 MySQL Global Business Unit Shinya Sugiyama

Upload: shinya-sugiyama

Post on 13-Jan-2017

226 views

Category:

Software


0 download

TRANSCRIPT

Page 1: 20160104 my sql_with_docker

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

MySQL on Docker Created: 2016/01/04 Updated: 2016/01/05

MySQL Global Business Unit Shinya Sugiyama

Page 2: 20160104 my sql_with_docker

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

以下の事項は、弊社の一般的な製品の方向性に関する概要を説明するものです。 また、情報提供を唯一の目的とするものであり、いかなる契約にも組み込むことはできません。 以下の事項は、マテリアルやコード、機能を提供することをコミットメントするものではない為、購買決定を行う際の判断材料になさらないで下さい。 オラクル製品に関して記載されている機能の開発、リリースおよび時期については、 弊社の裁量により決定されます。

SAFE HARBOR STATEMENT

2

Page 3: 20160104 my sql_with_docker

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |

Dockerはオープンソースの

コンテナ管理ソフトウエア

ゲストOSが無く、ホストOSのカーネルを共有

コンピュートリソースの分離

コンテナ間でプロセス・リソース分離 (1コンテナ=1プロセス)

コンテナ間でネットワーク構成分離

ファイル/ディレクトリの世代と差分の管理

※ 迅速なデプロイと管理工数の削減をサポート

3

Docker

Hyper Visor

仮想サーバ

OS

OS

コンテナ管理ソフト

コンテナ

Applications

Middle ware

Applications

Middle ware

※ Dockerドキュメント https://docs.docker.com/

Docker, Inc and Docker Open Source Project Container Management

Page 5: 20160104 my sql_with_docker

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 5

MySQL on Docker Preparation

# docker pull mysql:5.7.10

5.7.10: Pulling from library/mysql

9ee13ca3b908: Pull complete

23cb15b0fcec: Pull complete

………

# docker run --name mysql5710 -e MYSQL_ROOT_PASSWORD=mysql -d mysql:5.7.10

10d793b6cd27888918a067978c52a370cd47dfb3f

# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE mysql latest ea0aca21950d 2 weeks ago 360.3 MB mysql 5.7.10 ea0aca21950d 2 weeks ago 360.3 MB mysql 5.7.8 6716cba3de7a 11 weeks ago 358.2 MB

# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a8f670f1cc9d mysql:5.7.10 "/entrypoint.sh mysql" 6 days ago Exited (0) 2 days ago mysql5710_02 3c30bb901664 mysql:5.7.10 "/entrypoint.sh mysql" 6 days ago Exited (0) 2 days ago mysql5710 #

イメージのダウンロードとインストレーション

Page 6: 20160104 my sql_with_docker

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 6

MySQL on Docker Preparation

#docker run --name mysql5710_control -v /docker/data2:/var/lib/mysql -v /docker/option2:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=mysql -d mysql:5.7.10

# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8c39c00fb684 mysql:5.7.10 "/entrypoint.sh mysql" 1 days ago Up 2 seconds 3306/tcp mysql5710_control a8f670f1cc9d mysql:5.7.10 "/entrypoint.sh mysql" 6 days ago Exited (0) 2 days ago mysql5710_02 3c30bb901664 mysql:5.7.10 "/entrypoint.sh mysql" 6 days ago Exited (0) 2 days ago mysql5710 # docker inspect -f "{{.Config.Hostname}}, {{.NetworkSettings.IPAddress}}" $(docker ps | grep -v "^CONTAINER" | awk '{print $1}') 8c39c00fb684, 172.17.0.2

# docker exec -it mysql5710_control mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or ¥g. Your MySQL connection id is 2 Server version: 5.7.10-log MySQL Community Server (GPL) mysql> show variables like '%character_set_database%'; +------------------------+-------+ | Variable_name | Value | +------------------------+-------+ | character_set_database | utf8 | +------------------------+-------+

データディレクトリーやオプションファイルの指定も可能

-v オプション オプションファイルやデータ ディレクトリーを指定する事も可能。

# docker inspect mysql5710_control | egrep 'Source|Destination' "Source": "/docker/option2", "Destination": "/etc/mysql/conf.d", "Source": "/docker/data2", "Destination": "/var/lib/mysql", #

Page 7: 20160104 my sql_with_docker

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 7

その他、起動後の設定変更やイメージの永続化等 (volume)

MySQL on Docker Preparation

mysql> select user,host from mysql.user; +-------+------+ | user | host | +-------+------+ | admin | % | | root | % | +-------+------+ 2 rows in set (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | | world | +--------------------+ 5 rows in set (0.00 sec)

mysql> show variables like 'innodb_buffer_pool_size'; +-------------------------+----------+ | Variable_name | Value | +-------------------------+----------+ | innodb_buffer_pool_size | 67108864 | +-------------------------+----------+ 1 row in set (0.00 sec)

Page 8: 20160104 my sql_with_docker

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 8

MySQL on Docker Preparation

# docker run --name mysql5710_Node4 -v /docker/data4:/var/lib/mysql -v /docker/option4:/etc/mysql/conf.d -v /docker/init_scripts/sakila-db:/docker-entrypoint-initdb.d -e MYSQL_ROOT_PASSWORD=mysql -d mysql:5.7.10 7ba8b8f11d65af6a0e4c08a2a91f8c19550b8cf287d39d6233bfb6c4d3685067 #

起動時にデータベースを作成する事も可能 (*.shか*.sqlファイルを指定したディレクトリーに配置)

# docker exec -it mysql5710_Node4 mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or ¥g. Your MySQL connection id is 2 Server version: 5.7.10-log MySQL Community Server (GPL) root@localhost [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sakila | | sys | +--------------------+ 5 rows in set (0.00 sec)

# pwd /docker/init_scripts/sakila-db # ls -l total 3344 -rw-r--r-- 1 root root 3421501 Jan 5 05:09 sakila-docker.sql #

Page 9: 20160104 my sql_with_docker

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 9

参考)

Docker user guide https://docs.docker.com/engine/userguide/ Optimized MySQL Server Docker images. Created, maintained and supported by the MySQL team at Oracle https://hub.docker.com/r/mysql/mysql-server/ MySQL-Docker operations. - Part 1: Getting started with MySQL in Docker http://datacharmer.blogspot.jp/2015/10/mysql-docker-operations-part-1-getting.html Docker MySQL Persistence (Tech Tip #83) http://blog.arungupta.me/

Page 10: 20160104 my sql_with_docker

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 10

Page 11: 20160104 my sql_with_docker