{"id":4482,"date":"2016-08-22T10:54:24","date_gmt":"2016-08-22T01:54:24","guid":{"rendered":"http:\/\/www.lancard.com\/blog\/?p=4482"},"modified":"2025-03-12T11:27:07","modified_gmt":"2025-03-12T02:27:07","slug":"docker%e5%85%ac%e5%bc%8f%e3%82%a4%e3%83%a1%e3%83%bc%e3%82%b8%e3%81%a7%e9%96%8b%e7%99%ba%e7%94%a8rdb%e3%82%92%e3%82%b2%e3%83%83%e3%83%88%e3%81%a0%e3%81%9cmysql%e7%b7%a8","status":"publish","type":"post","link":"https:\/\/www.lancard.com\/blog\/2016\/08\/22\/docker%e5%85%ac%e5%bc%8f%e3%82%a4%e3%83%a1%e3%83%bc%e3%82%b8%e3%81%a7%e9%96%8b%e7%99%ba%e7%94%a8rdb%e3%82%92%e3%82%b2%e3%83%83%e3%83%88%e3%81%a0%e3%81%9cmysql%e7%b7%a8\/","title":{"rendered":"Docker\u516c\u5f0f\u30a4\u30e1\u30fc\u30b8\u3067\u958b\u767a\u7528RDB\u3092\u30b2\u30c3\u30c8\u3060\u305c(MySQL\u7de8)"},"content":{"rendered":"<h1>\u307e\u3048\u304c\u304d<\/h1>\n<p><a href=\"http:\/\/www.lancard.com\/blog\/?p=4470\">Docker\u516c\u5f0f\u30a4\u30e1\u30fc\u30b8\u3067\u958b\u767a\u7528RDB\u3092\u30b2\u30c3\u30c8\u3060\u305c(PostgreSQL\u7de8)<\/a><\/p>\n<p>\u306b\u7d9a\u304dMySQL\u7de8\u3067\u3059\u3002Docker for Mac\u3092\u4f7f\u7528\u3057\u3066\u304a\u308a\u307e\u3059\u3002\u306f\u3058\u3081\u308b\u3088\u301c\u3002<\/p>\n<p><!--more--><\/p>\n<h1>MySQL<\/h1>\n<p><a href=\"http:\/\/dqn.sakusakutto.jp\/2015\/10\/docker_mysqld_tutorial.html\" target=\"_blank\">Docker\u306e\u516c\u5f0fMySQL\u30a4\u30e1\u30fc\u30b8\u306e\u4f7f\u3044\u65b9\u3092\u5fb9\u5e95\u7684\u306b\u89e3\u8aac\u3059\u308b\u3088<\/a><\/p>\n<p>\u3068\u3044\u3046\u7d20\u6575\u306a\u30da\u30fc\u30b8\u304c\u3042\u308a\u307e\u3057\u305f\u306e\u3067\u3053\u3061\u3089\u3082\u53c2\u8003\u306b\u3055\u305b\u3066\u3044\u305f\u3060\u3053\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h2>\u516c\u5f0f\u30a4\u30e1\u30fc\u30b8\u3092\u8abf\u3079\u308b<\/h2>\n<p><a href=\"https:\/\/hub.docker.com\/_\/mysql\/\" target=\"_blank\">OFFICIAL REPOSITORY mysql<\/a><\/p>\n<p>2016\u5e748\u6708\u4e2d\u65ec\u73fe\u5728\u3001\u4ee5\u4e0b\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u304c\u3042\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n<p>5.7(5.7.14), 5.6(5.6.32), 5.5(5.5.51)<\/p>\n<p>\u5c11\u306a\u3044\u6c17\u3082\u3057\u307e\u3059\u304c\u899a\u609f\u3092\u6c7a\u3081\u30665.5\u4ee5\u4e0a\u3067\u884c\u304d\u307e\u3057\u3087\u3046\u3002\u300c\u53e4\u3044MySQL\u6b7b\u3059\u3079\u3057\u300d\u3068\u3044\u3046\u610f\u601d\u3092\u611f\u3058\u307e\u3059\u3002<\/p>\n<h3>\u8d77\u52d5\u3059\u308b<\/h3>\n<p>latest\u306f5.7\u7cfb\u306e\u3088\u3046\u3067\u3059\u306e\u3067\u3001\u3042\u3048\u30665.5\u7cfb\u3067\u3059\u3059\u3081\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre><code>$ docker run -d --name mysql55 -e MYSQL_ROOT_PASSWORD=mysecretpassword -p 13306:3306 mysql:5.5\n<\/code><\/pre>\n<p>\u516c\u5f0f\u306e\u4f8b\u3092\u53c2\u8003\u306b\u30b3\u30f3\u30c6\u30ca\u306e3306\u309213306\u306b\u30dd\u30fc\u30c8\u30d5\u30a9\u30ef\u30fc\u30c9\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h3>\u63a5\u7d9a\u3059\u308b<\/h3>\n<p>mysql\u30b3\u30de\u30f3\u30c9\u3067\u63a5\u7d9a\u3057\u307e\u3059\u3002\u516c\u5f0f\u306e\u4f8b\u306f\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30b3\u30f3\u30c6\u30ca\u3067env\u306e\u60c5\u5831\u3092\u5229\u7528\u3057\u3066\u4e00\u6c17\u306b\u3064\u306a\u3050\u65b9\u6cd5\u3067\u3059\u306d\u3002<\/p>\n<pre><code>$ docker run -it --link mysql55:mysql --rm mysql:5.5 sh -c 'exec mysql -h\"$MYSQL_PORT_3306_TCP_ADDR\" -P\"$MYSQL_PORT_3306_TCP_PORT\" -uroot -p\"$MYSQL_ENV_MYSQL_ROOT_PASSWORD\"'\nWelcome to the MySQL monitor.  Commands end with ; or \\g.\nYour MySQL connection id is 4\nServer version: 5.5.51 MySQL Community Server (GPL)\n\nCopyright (c) 2000, 2016, Oracle and\/or its affiliates. All rights reserved.\n\nOracle is a registered trademark of Oracle Corporation and\/or its\naffiliates. Other names may be trademarks of their respective\nowners.\n\nType 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\n\nmysql&gt; SHOW DATABASES;\n+--------------------+\n| Database           |\n+--------------------+\n| information_schema |\n| mysql              |\n| performance_schema |\n+--------------------+\n3 rows in set (0.00 sec)\n\nmysql&gt; select Host, User from mysql.user;\n+------+------+\n| Host | User |\n+------+------+\n| %    | root |\n+------+------+\n1 row in set (0.00 sec)\n\nmysql&gt; exit\nBye\n\n<\/code><\/pre>\n<p>\u4fbf\u5229\u3060\u3051\u3069\u9577\u3044\u301c\u3002\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u306b\u3067\u3082\u3057\u3066\u304a\u304f\u306e\u304c\u3088\u3044\u3067\u3057\u3087\u3046\u304b\u3002client\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u3044\u3066\u5b9f\u884c\u6a29\u9650\u3092\u4ed8\u3051\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<pre><code>$ .\/client \nWelcome to the MySQL monitor.  Commands end with ; or \\g.\nYour MySQL connection id is 5\nServer version: 5.5.51 MySQL Community Server (GPL)\n\nCopyright (c) 2000, 2016, Oracle and\/or its affiliates. All rights reserved.\n\nOracle is a registered trademark of Oracle Corporation and\/or its\naffiliates. Other names may be trademarks of their respective\nowners.\n\nType 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\n\nmysql&gt; \n<\/code><\/pre>\n<p>\u304a\u3051\u304a\u3051\u3002PostgreSQL\u306e\u65b9\u306b\u3082\u4f5c\u3063\u3066\u304a\u3053\u3046\u304b\u306a\u3002<\/p>\n<p>\u6b21\u306b Sequel Pro \u5148\u751f\u3067\u7e4b\u3044\u3067\u307f\u307e\u3059\u300213306\u306b\u30dd\u30fc\u30c8\u30d5\u30a9\u30ef\u30fc\u30c9\u3057\u3066\u307e\u3059\u306e\u3067<\/p>\n<p><a href=\"http:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2016\/08\/c7d50a5bbabd55d715ed76332eeb4c06.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2016\/08\/c7d50a5bbabd55d715ed76332eeb4c06-400x230.jpg\" alt=\"Sequel\u3067\u63a5\u7d9a(\u63a5\u7d9a\u60c5\u5831)\" width=\"400\" height=\"230\" class=\"alignnone size-medium wp-image-4484\" srcset=\"https:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2016\/08\/c7d50a5bbabd55d715ed76332eeb4c06-400x230.jpg 400w, https:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2016\/08\/c7d50a5bbabd55d715ed76332eeb4c06-768x442.jpg 768w, https:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2016\/08\/c7d50a5bbabd55d715ed76332eeb4c06-602x347.jpg 602w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/a><\/p>\n<p>\u30b5\u30af\u30c3\u3068\u7e4b\u304c\u308a\u307e\u3057\u305f\u3002<\/p>\n<p><a href=\"http:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2016\/08\/MySQL_5_5_51__local13306_mysql_db.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2016\/08\/MySQL_5_5_51__local13306_mysql_db-400x231.jpg\" alt=\"Sequel\u3067\u64cd\u4f5c\" width=\"400\" height=\"231\" class=\"alignnone size-medium wp-image-4486\" srcset=\"https:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2016\/08\/MySQL_5_5_51__local13306_mysql_db-400x231.jpg 400w, https:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2016\/08\/MySQL_5_5_51__local13306_mysql_db-768x443.jpg 768w, https:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2016\/08\/MySQL_5_5_51__local13306_mysql_db-602x347.jpg 602w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/a><\/p>\n<p>mysql\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u4e2d\u306a\u3069\u8997\u3044\u3066\u307f\u305f\u308a\u3002\u697d\u3061\u3093\u3002<\/p>\n<h3>\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306a\u3069<\/h3>\n<p>\u30b3\u30f3\u30c6\u30ca\u306e\u30b7\u30a7\u30eb\u3092\u8d77\u52d5\u3057\u3066\u63a2\u691c\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre><code>$ docker exec -it mysql55 bash  \n<\/code><\/pre>\n<p>\u3068\u308a\u3042\u3048\u305amy.cnf\u3092\u773a\u3081\u3066\u307f\u308b\u3002<\/p>\n<pre><code>root@688eab40f1a8:\/# more \/etc\/mysql\/my.cnf\n[mysqld]\nskip-host-cache\nskip-name-resolve\ndatadir = \/var\/lib\/mysql\n!includedir \/etc\/mysql\/conf.d\/\n<\/code><\/pre>\n<p>\/etc\/mysql\/conf.d\/ \u306ecnf\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3080\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u306d\u3002<\/p>\n<h3>\u62e1\u5f35\u3059\u308b<\/h3>\n<p>\u3044\u308d\u3044\u308d\u306a\u65b9\u6cd5\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n<p>\u307e\u305a\u3001\u5148\u307b\u3069\u8abf\u3079\u305f\u3088\u3046\u306b\u30b3\u30f3\u30c6\u30ca\u306e \/etc\/mysql\/conf.d\/ \u306bcnf\u30d5\u30a1\u30a4\u30eb\u3092\u7f6e\u304f\u3068\u8aad\u307f\u8fbc\u307e\u308c\u307e\u3059\u3002<\/p>\n<p>PostgreSQL\u306e\u516c\u5f0f\u30a4\u30e1\u30fc\u30b8\u3068\u540c\u3058\u304f\u30b3\u30f3\u30c6\u30ca\u306e \/docker-entrypoint-initdb.d \u306b\u62e1\u5f35\u5b50\u304csh\u3001sql\u3001sql.gz\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u7f6e\u304f\u3068\u30b3\u30f3\u30c6\u30ca\u8d77\u52d5\u6642\u306b\u5b9f\u884c\u3057\u3066\u304f\u308c\u307e\u3059\u3002mysql\/5.5\/docker-entrypoint.sh\u3092\u773a\u3081\u3066\u307f\u305f\u3068\u3053\u308d\u3001<\/p>\n<pre><code>for f in \/docker-entrypoint-initdb.d\/*; do\n    case \"$f\" in\n        *.sh)     echo \"$0: running $f\"; . \"$f\" ;;\n        *.sql)    echo \"$0: running $f\"; \"${mysql[@]}\" &lt; \"$f\"; echo ;;\n        *.sql.gz) echo \"$0: running $f\"; gunzip -c \"$f\" | \"${mysql[@]}\"; echo ;;\n        *)        echo \"$0: ignoring $f\" ;;\n    esac\n    echo\ndone\n<\/code><\/pre>\n<p>\u3053\u306e\u3088\u3046\u306b\u4ed5\u7d44\u307f\u3082\u540c\u3058\u611f\u3058\u3067\u3057\u305f\u3002<\/p>\n<p>\u4ed6\u3001PostgreSQL\u306e\u6642\u3068\u540c\u3058\u3088\u3046\u306b\u65e5\u672c\u8a9e\u5316\u3055\u308c\u305f\u30a4\u30e1\u30fc\u30b8\u3092\u4f5c\u308d\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h4>\u65e5\u672c\u8a9e\u5316\u3055\u308c\u305f\u30a4\u30e1\u30fc\u30b8\u306e\u4f5c\u6210<\/h4>\n<p>PostgreSQL\u3067\u306e\u3084\u308a\u65b9\u3092\u53c2\u8003\u306bdefault locale\u3092\u8a2d\u5b9a\u3059\u308bDockerfile\u3092\u4f5c\u308a\u307e\u3059\u3002<\/p>\n<p>Dockerfile<\/p>\n<pre><code>FROM mysql:5.5\n\nMAINTAINER murave\n\nRUN apt-get update &amp;&amp; apt-get install locales -y &amp;&amp; localedef -i ja_JP -c -f UTF-8 -A \/usr\/share\/locale\/locale.alias ja_JP.UTF-8\nENV LANG ja_JP.utf8\n<\/code><\/pre>\n<p>\u516c\u5f0f\u30a4\u30e1\u30fc\u30b8\u306b\u306flocales\u304c\u5165\u3063\u3066\u3044\u306a\u304b\u3063\u305f\u306e\u3067localedef\u306e\u524d\u306bapt-get\u3067\u5c0e\u5165\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u65e5\u672c\u8a9e\u5316\u3055\u308c\u305f\u30a4\u30e1\u30fc\u30b8\u3001mysql_jp:5.5\u3092\u4f5c\u308a\u307e\u3059\u3002<\/p>\n<pre><code>$ docker build -t mysql_jp:5.5 .\/\n<\/code><\/pre>\n<p>\u78ba\u8a8d<\/p>\n<pre><code>$ docker images\nREPOSITORY           TAG                 IMAGE ID            CREATED             SIZE\nmysql_jp             5.5                 42465a1c94d5        22 minutes ago      284.5 MB\n<\/code><\/pre>\n<h4>\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306e\u8abf\u6574<\/h4>\n<p>\/etc\/mysql\/conf.d\/ \u306b\u30d0\u30a4\u30f3\u30c9\u3059\u308b\u30c7\u30a3\u30ec\u30af\u30c8\u30eaconf.d\u3092\u4f5c\u6210\u3057\u3066\u8ffd\u52a0\u306e\u8a2d\u5b9a\u3092\u66f8\u3044\u305fcnf\u30d5\u30a1\u30a4\u30eb\u3092\u7f6e\u304d\u307e\u3059\u3002<\/p>\n<p>conf.d\/custom.cnf<\/p>\n<pre><code>[mysqld]\ncharacter-set-server=utf8\n<\/code><\/pre>\n<p>Mac\u4e0a\u306econd.d\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\/etc\/mysql\/conf.d\u306b\u30d0\u30a4\u30f3\u30c9\u3059\u308b\u3088\u3046\u306b\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u4ed8\u3051\u3066\u8d77\u52d5\u3057\u307e\u3059\u3002<\/p>\n<pre><code>$ docker run -d --name mysql55  -e MYSQL_ROOT_PASSWORD=mysecretpassword -p 13306:3306 -v $(pwd)\/conf.d\/:\/etc\/mysql\/conf.d mysql_jp:5.5\n<\/code><\/pre>\n<p>exec\u3067\u30b3\u30f3\u30c6\u30ca\u4e0a\u306e\/etc\/mysql\/conf.d\u306els\u7d50\u679c\u3092\u898b\u3066\u30d0\u30a4\u30f3\u30c9\u3055\u308c\u3066\u3044\u308b\u304b\u78ba\u8a8d\u3002<\/p>\n<pre><code>$ docker exec -it mysql55 ls \/etc\/mysql\/conf.d\ncustom.cnf\n<\/code><\/pre>\n<p>\u304a\u3051\u304a\u3051\u3002<\/p>\n<h4>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u521d\u671f\u5316<\/h4>\n<p>\u30a2\u30ab\u30a6\u30f3\u30c8\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u4f5c\u6210\u306f\u8a2d\u5b9a\u7528\u306b\u6e96\u5099\u3055\u308c\u305f\u74b0\u5883\u5909\u6570(MYSQL_USER\u3001MYSQL_PASSWORD\u3001MYSQL_DATABASE)\u3092\u5229\u7528\u3057\u3001\/docker-entrypoint-initdb.d \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u5b9f\u884c\u3092\u5229\u7528\u3057\u3066\u30c6\u30fc\u30d6\u30eb\u4f5c\u6210\u306a\u3069\u3092\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u30e6\u30fc\u30b6\u30fc\u3092foo\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092foodb\u3068\u3059\u308b\u524d\u63d0\u3067\u521d\u671f\u5316\u7528\u306esql\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u308a\u307e\u3059\u3002<br \/>\ninitdb\/01createtable.sql<\/p>\n<pre><code>CREATE TABLE foodb.users (id int , name varchar(255));\nGRANT ALL ON foodb.users TO foo;\nINSERT INTO foodb.users (id, name) VALUES (1, 'first'), (1, 'second')\n<\/code><\/pre>\n<p>foodb\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306busers\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3057\u30e6\u30fc\u30b6\u30fcfoo\u306b\u6a29\u9650\u3092\u4e0e\u3048\u3001users\u30c6\u30fc\u30d6\u30eb\u306b\u521d\u671f\u5024\u3092INSERT\u6587\u3067\u6295\u5165\u3068\u3044\u3046\u30b7\u30ca\u30ea\u30aa\u3067\u3059\u3002<\/p>\n<p>\/docker-entrypoint-initdb.d \u3092\u30d0\u30a4\u30f3\u30c9\u3057\u3066\u8d77\u52d5\u3002<\/p>\n<pre><code>$ docker run -d --name mysql55 -e MYSQL_DATABASE=foodb -e MYSQL_USER=foo -e MYSQL_PASSWORD=foopassword -e MYSQL_ROOT_PASSWORD=mysecretpassword -p 13306:3306 -v $(pwd)\/conf.d\/:\/etc\/mysql\/conf.d -v $(pwd)\/initdb\/:\/docker-entrypoint-initdb.d mysql_jp:5.5\n<\/code><\/pre>\n<p>\u78ba\u8a8d\u3057\u307e\u3059\u3002<\/p>\n<pre><code>$ .\/client \nWelcome to the MySQL monitor.  Commands end with ; or \\g.\nYour MySQL connection id is 2\nServer version: 5.5.51 MySQL Community Server (GPL)\n\nCopyright (c) 2000, 2016, Oracle and\/or its affiliates. All rights reserved.\n\nOracle is a registered trademark of Oracle Corporation and\/or its\naffiliates. Other names may be trademarks of their respective\nowners.\n\nType 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\n\nmysql&gt; SHOW DATABASES;\n+--------------------+\n| Database           |\n+--------------------+\n| information_schema |\n| foodb              |\n| mysql              |\n| performance_schema |\n+--------------------+\n4 rows in set (0.00 sec)\n\nmysql&gt; select Host, User from mysql.user;\n+------+------+\n| Host | User |\n+------+------+\n| %    | foo  |\n| %    | root |\n+------+------+\n2 rows in set (0.00 sec)\n\nmysql&gt; USE foodb;\nReading table information for completion of table and column names\nYou can turn off this feature to get a quicker startup with -A\n\nDatabase changed\nmysql&gt; SHOW TABLES;\n+-----------------+\n| Tables_in_foodb |\n+-----------------+\n| users           |\n+-----------------+\n1 row in set (0.01 sec)\n\nmysql&gt; SELECT * from users;\n+------+--------+\n| id   | name   |\n+------+--------+\n|    1 | first  |\n|    1 | second |\n+------+--------+\n2 rows in set (0.00 sec)\n\nmysql&gt; exit\nBye\n<\/code><\/pre>\n<p>\u60f3\u5b9a\u901a\u308a\u306b\u521d\u671f\u5316\u3055\u308c\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n<h5>\u30b9\u30af\u30ea\u30d7\u30c8\u5b9f\u884c\u306b\u3064\u3044\u3066\u306e\u60b2\u3057\u3044\u88dc\u8db3\u60c5\u5831<\/h5>\n<p>\u306f\u3058\u3081\u306fsql\u30d5\u30a1\u30a4\u30eb\u3067\u306f\u306a\u304fsh\u30d5\u30a1\u30a4\u30eb(\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8)\u5185\u3067mysql\u30b3\u30de\u30f3\u30c9\u3092\u547c\u3073\u51fa\u3057\u3066\u521d\u671f\u5316\u3057\u3088\u3046\u3068\u3057\u3066\u3044\u307e\u3057\u305f\u3002\u5b9f\u969b\u306b\u4f7f\u7528\u3059\u308b\u30e6\u30fc\u30b6\u30fc\u3067\u30c6\u30fc\u30d6\u30eb\u4f5c\u6210\u3084\u30c7\u30fc\u30bf\u6295\u5165\u3057\u305f\u3044\u3058\u3083\u306a\u3044\u3067\u3059\u304b\u3002\u6c17\u5206\u7684\u306b\u3002<\/p>\n<p>initdb\/01createtable.sh<\/p>\n<pre><code>!\/bin\/bash\nset -e\n\nmysql -u\"$MYSQL_USER\" -p\"$MYSQL_PASSWORD\" $MYSQL_DATABASE &lt;&lt;-EOSQL\n    CREATE TABLE users (id int , name varchar(255));\nEOSQL\n<\/code><\/pre>\n<p>\u3053\u306e\u3088\u3046\u306a\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u30c6\u30fc\u30d6\u30eb\u4f5c\u6210\u306f\u884c\u308f\u308c\u308b\u306e\u3067\u3059\u304csh\u30b9\u30af\u30ea\u30d7\u30c8\u5b9f\u884c\u5f8c\u306b\u30b3\u30f3\u30c6\u30ca\u304cExit\u3057\u3066\u3057\u307e\u3046\u3068\u3044\u3046\u75c7\u72b6\u304c\u767a\u751f\u3002\u89e3\u6c7a\u51fa\u6765\u305a\u306b\u30cf\u30de\u308a\u307e\u304f\u308a\u3001sql\u30d5\u30a1\u30a4\u30eb\u3067\u306e\u521d\u671f\u5316\u306b\u65b9\u91dd\u5909\u66f4\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u306e\u5f8c\u3001\u843d\u3061\u7740\u3044\u3066\u516c\u5f0f\u30a4\u30e1\u30fc\u30b8\u306e\u30da\u30fc\u30b8\u3092\u898b\u306a\u304a\u3057\u3066\u3044\u308b\u3068<\/p>\n<blockquote><p>\n  No connections until MySQL init completes\n<\/p><\/blockquote>\n<p>\u3068\u3044\u3046\u9805\u76ee\u304c\u3042\u308b\u306e\u306b\u6c17\u4ed8\u304d\u307e\u3057\u305f\u3002mysql\u30b3\u30de\u30f3\u30c9\u3067\u63a5\u7d9a\u3057\u3066\u3044\u308b\u306e\u304c\u539f\u56e0\u3063\u307d\u3044\u3067\u3059\u306d\u3002<\/p>\n<h2>Docker Compose \u3067\u958b\u767a\u7528\u306e MySQL \u3092\u8d77\u52d5\u3059\u308b<\/h2>\n<p>\u65e5\u672c\u8a9e\u5316\u3057\u305f\u30a4\u30e1\u30fc\u30b8\u3092\u4f7f\u7528\u3057conf.d\u306ecnf\u30d5\u30a1\u30a4\u30eb\u3067\u8a2d\u5b9a\u8abf\u6574\u3001initdb\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u521d\u671f\u5316\u3001\u30c7\u30fc\u30bf\u306e\u6c38\u7d9a\u5316\u306fbusybox\u3092\u4f7f\u7528\u3059\u308b\u65b9\u91dd\u3067docker-compose.yml\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/qiita.com\/astrsk_hori\/items\/1e683a7a2f2b7189cb6e\" target=\"_blank\">docker-compose\u3067mysql &amp; postgreSQL \u3092\u30b5\u30af\u30c3\u3068\u8d77\u52d5<\/a><\/p>\n<p>\u3092\u53c2\u8003\u306b\u3055\u305b\u3066\u3044\u305f\u3060\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>docker-compose.yml<\/p>\n<pre><code>datastore:\n  image: busybox\n  volumes:\n    - \/var\/lib\/mysql\n  container_name: mysql-datastore\n\nmysql:\n  image: mysql_jp:5.5\n  environment:\n    MYSQL_ROOT_PASSWORD: mysecretpassword\n    MYSQL_USER: foo\n    MYSQL_PASSWORD: foopassword\n    MYSQL_DATABASE: foodb\n  volumes:\n    - .\/conf.d\/:\/etc\/mysql\/conf.d\n    - .\/initdb\/:\/docker-entrypoint-initdb.d\n  ports:\n    - \"13306:3306\"\n  volumes_from:\n    - datastore\n  container_name: mysql-db\n<\/code><\/pre>\n<p>\u8d77\u52d5\u3057\u307e\u3059\u3002<\/p>\n<pre><code>$ docker-compose up -d        \nCreating mysql-datastore\nCreating mysql-db\n<\/code><\/pre>\n<p>\u4ee5\u964d\u3001\u4f7f\u7528\u3059\u308b\u3042\u3044\u3060\u306fstop\u30fbstart\u3067\u505c\u6b62\u30fb\u8d77\u52d5\u3002<\/p>\n<p>mysql\u30b3\u30de\u30f3\u30c9\u3067\u306e\u63a5\u7d9a\u7528\u306eclient\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u30b3\u30f3\u30c6\u30ca\u540d\u3092mysql-db\u306b\u4fee\u6b63\u3057\u3066\u63a5\u7d9a\u3057\u3066\u52d5\u4f5c\u3092\u78ba\u8a8d\u3002<br \/>\nSequel Pro \u3092\u4f7f\u3044\u30dd\u30fc\u30c8\u30d5\u30a9\u30ef\u30fc\u30c9\u3057\u305f13306\u306b\u30e6\u30fc\u30b6\u30fcfoo\u3067foodb\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u63a5\u7d9a\u3057\u3066\u306e\u64cd\u4f5c\u3082\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u30d5\u30a1\u30a4\u30eb\u69cb\u6210\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<pre><code class=\"text\">.\n\u251c\u2500\u2500 Dockerfile\n\u251c\u2500\u2500 client\n\u251c\u2500\u2500 conf.d\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 custom.cnf\n\u251c\u2500\u2500 docker-compose.yml\n\u2514\u2500\u2500 initdb\n    \u2514\u2500\u2500 01createtable.sql\n<\/code><\/pre>\n<a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-facebook nolightbox\" data-provider=\"facebook\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Facebook\" href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F4482&#038;t=Docker%E5%85%AC%E5%BC%8F%E3%82%A4%E3%83%A1%E3%83%BC%E3%82%B8%E3%81%A7%E9%96%8B%E7%99%BA%E7%94%A8RDB%E3%82%92%E3%82%B2%E3%83%83%E3%83%88%E3%81%A0%E3%81%9C%28MySQL%E7%B7%A8%29&#038;s=100&#038;p&#091;url&#093;=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F4482&#038;p&#091;images&#093;&#091;0&#093;=http%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-content%2Fuploads%2F2016%2F08%2Fc7d50a5bbabd55d715ed76332eeb4c06-400x230.jpg&#038;p&#091;title&#093;=Docker%E5%85%AC%E5%BC%8F%E3%82%A4%E3%83%A1%E3%83%BC%E3%82%B8%E3%81%A7%E9%96%8B%E7%99%BA%E7%94%A8RDB%E3%82%92%E3%82%B2%E3%83%83%E3%83%88%E3%81%A0%E3%81%9C%28MySQL%E7%B7%A8%29\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"Facebook\" title=\"Share on Facebook\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/facebook.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-twitter nolightbox\" data-provider=\"twitter\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Twitter\" href=\"http:\/\/twitter.com\/share?url=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F4482&#038;text=Docker%E5%85%AC%E5%BC%8F%E3%82%A4%E3%83%A1%E3%83%BC%E3%82%B8%E3%81%A7%E9%96%8B%E7%99%BA%E7%94%A8RDB%E3%82%92%E3%82%B2%E3%83%83%E3%83%88%E3%81%A0%E3%81%9C%28MySQL%E7%B7%A8%29\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"twitter\" title=\"Share on Twitter\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/twitter.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-linkedin nolightbox\" data-provider=\"linkedin\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Linkedin\" href=\"https:\/\/www.linkedin.com\/shareArticle?mini=true&#038;url=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F4482&#038;title=Docker%E5%85%AC%E5%BC%8F%E3%82%A4%E3%83%A1%E3%83%BC%E3%82%B8%E3%81%A7%E9%96%8B%E7%99%BA%E7%94%A8RDB%E3%82%92%E3%82%B2%E3%83%83%E3%83%88%E3%81%A0%E3%81%9C%28MySQL%E7%B7%A8%29\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"linkedin\" title=\"Share on Linkedin\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/linkedin.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-tumblr nolightbox\" data-provider=\"tumblr\" target=\"_blank\" rel=\"nofollow\" title=\"Share on tumblr\" href=\"https:\/\/tumblr.com\/share?s=&#038;v=3&#038;t=Docker%E5%85%AC%E5%BC%8F%E3%82%A4%E3%83%A1%E3%83%BC%E3%82%B8%E3%81%A7%E9%96%8B%E7%99%BA%E7%94%A8RDB%E3%82%92%E3%82%B2%E3%83%83%E3%83%88%E3%81%A0%E3%81%9C%28MySQL%E7%B7%A8%29&#038;u=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F4482\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"tumblr\" title=\"Share on tumblr\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/tumblr.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-mail nolightbox\" data-provider=\"mail\" rel=\"nofollow\" title=\"Share by email\" href=\"mailto:?subject=Docker%E5%85%AC%E5%BC%8F%E3%82%A4%E3%83%A1%E3%83%BC%E3%82%B8%E3%81%A7%E9%96%8B%E7%99%BA%E7%94%A8RDB%E3%82%92%E3%82%B2%E3%83%83%E3%83%88%E3%81%A0%E3%81%9C%28MySQL%E7%B7%A8%29&#038;body=%E3%82%B7%E3%82%A7%E3%82%A2%E3%81%99%E3%82%8B%EF%BC%9A:%20https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F4482\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"mail\" title=\"Share by email\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/mail.png\" \/><\/a>","protected":false},"excerpt":{"rendered":"<p>\u307e\u3048\u304c\u304d Docker\u516c\u5f0f\u30a4\u30e1\u30fc\u30b8\u3067\u958b\u767a\u7528RDB\u3092\u30b2\u30c3\u30c8\u3060\u305c(PostgreSQL\u7de8) \u306b\u7d9a\u304dMySQL\u7de8\u3067\u3059\u3002Docker for Mac\u3092\u4f7f\u7528\u3057\u3066\u304a\u308a\u307e\u3059\u3002\u306f\u3058\u3081\u308b\u3088\u301c\u3002<\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48,61],"tags":[153,138],"class_list":["post-4482","post","type-post","status-publish","format-standard","hentry","category-mac","category-mysql","tag-docker","tag-mysql"],"_links":{"self":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts\/4482","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/comments?post=4482"}],"version-history":[{"count":8,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts\/4482\/revisions"}],"predecessor-version":[{"id":4573,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts\/4482\/revisions\/4573"}],"wp:attachment":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/media?parent=4482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/categories?post=4482"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/tags?post=4482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}