{"id":1833,"date":"2021-02-28T17:52:57","date_gmt":"2021-02-28T08:52:57","guid":{"rendered":"https:\/\/nobunobu1717.site\/?p=1833"},"modified":"2021-02-28T17:54:40","modified_gmt":"2021-02-28T08:54:40","slug":"post-1833","status":"publish","type":"post","link":"https:\/\/nobunobu1717.site\/?p=1833","title":{"rendered":"DockerCompose\u3067MacOS\u4e0a\u306bMySQL\u74b0\u5883\u3092\u69cb\u7bc9\u3059\u308b"},"content":{"rendered":"<div id=\"toc_container\" class=\"no_bullets\"><p class=\"toc_title\">Contents<\/p><ul class=\"toc_list\"><li><a href=\"#i\"><span class=\"toc_number toc_depth_1\">1<\/span> \u6982\u8981<\/a><\/li><li><a href=\"#i-2\"><span class=\"toc_number toc_depth_1\">2<\/span> \u524d\u63d0<\/a><\/li><li><a href=\"#i-3\"><span class=\"toc_number toc_depth_1\">3<\/span> \u624b\u9806<\/a><\/li><li><a href=\"#i-4\"><span class=\"toc_number toc_depth_1\">4<\/span> \u906d\u9047\u3057\u305f\u30a8\u30e9\u30fc<\/a><\/li><\/ul><\/div>\n<h2><span id=\"i\">\u6982\u8981<\/span><\/h2>\n<p>Mac\u306eDocker\u4e0a\u3067DockerCompose\u3092\u4f7f\u7528\u3057\u3066MySQL\u74b0\u5883\u3092\u69cb\u7bc9\u3057\u3066\u52d5\u305b\u308b\u307e\u3067\u306e\u30e1\u30e2\u3067\u3059\u3002<br \/>\n\u4ee5\u524dPostgresSQL\u3067\u4f3c\u305f\u3088\u3046\u306a\u4e8b\u3092\u3084\u3063\u3066\u3044\u3066\u4e0b\u8a18\u3067\u7d39\u4ecb\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u4eca\u56de\u306f\u8272\u3005\u3068\u8a70\u307e\u3063\u3066\u4e0a\u624b\u304f\u3044\u304b\u306a\u3063\u305f\u306e\u3067\u30e1\u30e2\u3068\u3057\u3066\u6b8b\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/nobunobu1717.site\/?p=1229\" rel=\"noopener noreferrer\" target=\"_blank\">\u53c2\u8003\u8a18\u4e8b<\/a><\/p>\n<h2><span id=\"i-2\">\u524d\u63d0<\/span><\/h2>\n<p>Mac OS 11.2.1<br \/>\nDocker for Mac 3.1.0<\/p>\n\n\t<p style=\"color:#666;margin-bottom:5px;\">\u30b9\u30dd\u30f3\u30b5\u30fc\u30ea\u30f3\u30af<\/p>\n\t<div class=\"middle-ad\">\n\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\n\n<h2><span id=\"i-3\">\u624b\u9806<\/span><\/h2>\n<h3>docker-compose.yml\u4f5c\u6210<\/h3>\n<p>\u4efb\u610f\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u6210\u3057\u3066\u4e0b\u8a18\u306edocker-compose.yml\u3092\u4f5c\u6210\u3059\u308b<br \/>\n\u30d1\u30b9\u30ef\u30fc\u30c9\u3084DB\u540d\u306e\u8a2d\u5b9a\u7b49\u306f\u9069\u5b9c\u5909\u66f4\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n\u306a\u304a\u3001\u30db\u30b9\u30c8\u5074\u306f13306\u30dd\u30fc\u30c8\u3092MySQL\u3078\u63a5\u7d9a\u3059\u308b\u305f\u3081\u306e\u30dd\u30fc\u30c8\u3068\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:yaml decode:true \" >\r\nversion: \"3\"\r\nservices:\r\n  mysql:\r\n    build: # my_sql\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306eDockerfile\u3092\u4f7f\u7528\u3059\u308b\u3088\u3046\u306b\u8a2d\u5b9a\r\n      context: .\/my_sql\r\n      dockerfile: Dockerfile\r\n    container_name: mysql_db\r\n    environment:\r\n      MYSQL_ROOT_PASSWORD: rootpass # \u30eb\u30fc\u30c8\u30e6\u30fc\u30b6\u306e\u30d1\u30b9\u30ef\u30fc\u30c9\r\n      MYSQL_DATABASE: test_database # DB\u540d\u79f0\r\n      MYSQL_USER: user # \u30e6\u30fc\u30b6\u30a2\u30ab\u30a6\u30f3\u30c8\r\n      MYSQL_PASSWORD: pass # \u30d1\u30b9\u30ef\u30fc\u30c9\r\n      TZ: \"Asia\/Tokyo\"\r\n    volumes: # \u30db\u30b9\u30c8\u5074\u3078\u306e\u6c38\u7d9a\u5316\u30dc\u30ea\u30e5\u30fc\u30e0\u306e\u30de\u30c3\u30d4\u30f3\u30b0\r\n      - .\/my_sql\/db\/data:\/var\/lib\/mysql\r\n      - .\/my_sql\/db\/my.cnf:\/etc\/mysql\/conf.d\/my.cnf\r\n      - .\/my_sql\/db\/sql:\/docker-entrypoint-initdb.d\r\n    ports:\r\n      - 13306:3306\r\n\r\n<\/pre>\n<h3>\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u7b49\u306e\u4f5c\u6210<\/h3>\n<p>\u4e0b\u8a18\u306e\u7528\u306bdocker-compose.yml\u30d5\u30a1\u30a4\u30eb\u306e\u76f4\u4e0b\u306bmy_sql\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u6210\u3057\u3066\u4e2d\u306bDockerfile\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<br \/>\n(Dockerfile\u306e\u4e2d\u8eab\u306f\u5f8c\u8ff0)<br \/>\n\u5408\u308f\u305b\u3066\u6c38\u7d9a\u5316\u30dc\u30ea\u30e5\u30fc\u30e0\u306b\u30de\u30c3\u30d4\u30f3\u30b0\u3057\u305fdb\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3068\u305d\u306e\u914d\u4e0b\u306bdata,sql\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<br \/>\nmysql\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3068\u306a\u308bmy.cnf\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u69cb\u6210<\/p>\n<pre class=\"lang:batch decode:true \" > |- docker-compose.yml\r\n |- my_sql     \r\n |   |-Dockerfile\r\n |- db\r\n     |-data\r\n     |-sql \r\n     |-my.cnf\r\n<\/pre>\n\n\t<p style=\"color:#666;margin-bottom:5px;\">\u30b9\u30dd\u30f3\u30b5\u30fc\u30ea\u30f3\u30af<\/p>\n\t<div class=\"middle-ad\">\n\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\n\n<h3>Dockerfile\u4f5c\u6210<\/h3>\n<p>Dockerfile\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306b\u8a18\u8f09\u3059\u308b\u3002<br \/>\n\u4eca\u56de\u306f\u30d0\u30fc\u30b8\u30e7\u30f35.7\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b\u304c\u3001\u4efb\u610f\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u8a2d\u5b9a\u3059\u308b\u3002<\/p>\n<pre class=\"lang:default decode:true \" >\r\nFROM mysql:5.7\r\n# \u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092\u30db\u30b9\u30c8\u304b\u3089\u30b3\u30d4\u30fc\u3059\u308b\r\nADD .\/db\/my.cnf \/etc\/mysql\/conf.d\/my.cnf\r\nRUN chmod 644 \/etc\/mysql\/conf.d\/my.cnf\r\n# MySQL\u3092root\u3067\u5b9f\u884c\u3059\u308b\u8a2d\u5b9a\u306b\u66f8\u304d\u63db\u3048\u3066\u8d77\u52d5\u3059\u308b\r\nRUN sed -e 's\/^ *user *= *mysql$\/user = root\/' -i \/etc\/mysql\/my.cnf\r\n<\/pre>\n<h3>my.cnf\u306e\u4f5c\u6210<\/h3>\n<p>my.cnf\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306b\u8a18\u8f09\u3059\u308b\u3002<br \/>\n\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u6587\u5b57\u30b3\u30fc\u30c9\u304cUFT-8\u3067\u306f\u7121\u3044\u306e\u3067\u6307\u5b9a\u3059\u308b\u8a2d\u5b9a\u306a\u3069\u3092\u884c\u306a\u3063\u3066\u3044\u308b\u3002<\/p>\n<pre class=\"lang:default decode:true \" >\r\n[mysqld]\r\ncharacter-set-server=utf8mb4 # UTF8\u5bfe\u5fdc\r\ncollation-server=utf8mb4_unicode_ci\r\nexplicit-defaults-for-timestamp=1  # \u30c6\u30fc\u30d6\u30eb\u306bTimeStamp\u578b\u306e\u30ab\u30e9\u30e0\u3092\u3082\u3064\u5834\u5408\u3001\u63a8\u5968\r\nuser=mysql # \u5b9f\u884c\u30e6\u30fc\u30b6\u306e\u6307\u5b9a\r\n\r\n[client]\r\ndefault-character-set=utf8mb4 # UTF8\u5bfe\u5fdc\r\n<\/pre>\n<h3>\u30d3\u30eb\u30c9\u3068\u8d77\u52d5<\/h3>\n<p>\u4e0b\u8a18\u306e\u30b3\u30de\u30f3\u30c9\u3092docker-compose.yml\u30d5\u30a1\u30a4\u30eb\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u5185\u3067\u5b9f\u884c\u3059\u308b\u3002<\/p>\n<pre class=\"lang:batch decode:true \" title=\"\u30b3\u30de\u30f3\u30c9\" >docker-compose build<\/pre>\n<p>\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u306a\u3051\u308c\u3070\u6210\u529f\u3002<br \/>\n\uff08\u5f8c\u8ff0\u3059\u308b\u304c\u3001\u79c1\u306f\u3053\u3053\u3067\u4f55\u5ea6\u3082\u30a8\u30e9\u30fc\u304c\u51fa\u3066\u89e3\u6c7a\u306b\u6642\u9593\u3092\u8981\u3057\u305f\u3002\uff09<\/p>\n<p>\u4e0b\u8a18\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u5b9f\u969b\u306b\u30b3\u30f3\u30c6\u30ca\u3092\u7acb\u3061\u4e0a\u3052\u308b\u3002<\/p>\n<pre class=\"lang:batch decode:true \" title=\"\u30b3\u30de\u30f3\u30c9\" >docker-compose up -d<\/pre>\n<p>\u4e0b\u8a18\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u30b3\u30f3\u30c6\u30ca\u304c\u7acb\u3061\u4e0a\u304c\u3063\u3066\u3044\u308b\u304b\u3092\u78ba\u8a8d\u3059\u308b\u3002<\/p>\n<pre class=\"lang:batch decode:true \" title=\"\u30b3\u30de\u30f3\u30c9\" >docker-compose ps<\/pre>\n<p>\u30b3\u30f3\u30c6\u30ca\u304c\u7acb\u3061\u4e0a\u304c\u3063\u3066\u3044\u308c\u3070\u4e0b\u8a18\u306e\u3088\u3046\u306b\u8868\u793a\u3055\u308c\u308b\u3002<\/p>\n<pre class=\"lang:batch decode:true \" >\r\n  Name               Command             State                 Ports               \r\n-----------------------------------------------------------------------------------\r\nmysql_db   docker-entrypoint.sh mysqld   Up      0.0.0.0:13306->3306\/tcp, 33060\/tcp\r\n<\/pre>\n<p>\u6b62\u3081\u305f\u3044\u5834\u5408\u306f\u4e0b\u8a18\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3002<\/p>\n<pre class=\"lang:batch decode:true \" title=\"\u30b3\u30de\u30f3\u30c9\" >docker-compose stop<\/pre>\n\n\t<p style=\"color:#666;margin-bottom:5px;\">\u30b9\u30dd\u30f3\u30b5\u30fc\u30ea\u30f3\u30af<\/p>\n\t<div class=\"middle-ad\">\n\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\n\n<h3>\u63a5\u7d9a\u78ba\u8a8d<\/h3>\n<p>\u5b9f\u969b\u306b\u63a5\u7d9a\u3067\u304d\u308b\u304b\u78ba\u8a8d\u3092\u884c\u3046\u3002<br \/>\n\u4eca\u56de\u306f\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3068\u3057\u3066DBbeaver\u3092\u4f7f\u7528\u3059\u308b\u3002<br \/>\n\u672a\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306e\u5834\u5408\u3001\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3092\u4e88\u3081\u884c\u3046\u3002<\/p>\n<p>\u63a5\u7d9a\u8a2d\u5b9a\u3068\u3057\u3066\u4e0b\u8a18\u306b\u6ce8\u610f\u3059\u308b\u3002<br \/>\n1. \u63a5\u7d9a\u4f5c\u306flocalhost\u3067Port\u306f13306(docker-compose.yml\u3067\u8a2d\u5b9a\u3057\u305f\u30dd\u30fc\u30c8\u3002)<br \/>\n2. \u63a5\u7d9adatabase\u306ftest_database(docker-compose.yml\u3067\u8a2d\u5b9a\u3057\u305f\u5024\u3002)<br \/>\n3. \u8a8d\u8a3c\u306fuser,pass\u3092\u6307\u5b9a(docker-compose.yml\u3067\u8a2d\u5b9a\u3057\u305f\u5024\u3002)<\/p>\n<p>\u4e0a\u8a18\u306e\u8a2d\u5b9a\u306f\u63a5\u7d9a\u3067\u304d\u308c\u3070\u30aa\u30fc\u30b1\u30fc\u3002<\/p>\n<h2><span id=\"i-4\">\u906d\u9047\u3057\u305f\u30a8\u30e9\u30fc<\/span><\/h2>\n<p>\u4e0a\u8a18\u306e\u8d77\u52d5\u307e\u3067\u306b\u767a\u751f\u3057\u305f\u30a8\u30e9\u30fc\u306b\u95a2\u3057\u3066\u3002<\/p>\n<h3>\u305d\u306e\uff11<\/h3>\n<p>build\u30b3\u30de\u30f3\u30c9\u5b9f\u884c\u6642\u306b\u4e0b\u8a18\u306e\u3088\u3046\u306a\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u305f\u3002<\/p>\n<pre class=\"lang:batch decode:true \" >\r\n2021-02-28T03:00:15.566201Z 0 [ERROR] Fatal error: Please read \"Security\" section of the manual to find out how to run mysqld as root!\r\n<\/pre>\n<p>root\u30e6\u30fc\u30b6\u3067mysql\u3092\u8d77\u52d5\u3059\u308b\u306e\u304c\u7981\u6b62\u3068\u306a\u3063\u3066\u3044\u308b\u3088\u3046\u3067\u3001\u8d77\u52d5\u3059\u308b\u30e6\u30fc\u30b6\u3092\u5225\u9014\u6307\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3088\u3046\u3067\u3059\u3002<br \/>\nroot\u3067\u3082my.cnf\u306b\u5b9f\u884c\u3059\u308broot\u4ee5\u5916\u306e\u30e6\u30fc\u30b6\u3092\u6307\u5b9a\u3059\u308b\u4e8b\u3067\u89e3\u6c7a\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>user=mysql # \u5b9f\u884c\u30e6\u30fc\u30b6\u306e\u6307\u5b9a<\/p>\n<p>\u53c2\u8003<br \/>\nhttps:\/\/qiita.com\/yosida001\/items\/f7acb893843c550e0074<\/p>\n\n\t<p style=\"color:#666;margin-bottom:5px;\">\u30b9\u30dd\u30f3\u30b5\u30fc\u30ea\u30f3\u30af<\/p>\n\t<div class=\"middle-ad\">\n\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\n\n<h3>\u305d\u306e\uff12<\/h3>\n<p>build\u30b3\u30de\u30f3\u30c9\u5b9f\u884c\u6642\u306b\u4e0b\u8a18\u306e\u3088\u3046\u306a\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u305f\u3002<\/p>\n<pre class=\"lang:batch decode:true \" >\r\n2021-02-28T03:08:51.008126Z 0 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.\r\n2021-02-28T03:08:51.009299Z 0 [Note] Salting uuid generator variables, current_pid: 8, server_start_time: 1614481730, bytes_sent: 0, \r\n<\/pre>\n<p>MAC OS\u74b0\u5883\u3067\u3057\u304b\u767a\u751f\u3057\u306a\u3044\u3088\u3046\u3067\u3059\u304c\u3001\u66f8\u304d\u8fbc\u307f\u6a29\u9650\u304c\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3063\u3066\u4e0a\u624b\u304f\u66f8\u304d\u8fbc\u3081\u3066\u3044\u306a\u3044\u305f\u3081\u3001root\u30e6\u30fc\u30b6\u8d77\u52d5\u306b\u3059\u308b\u3053\u3068\u3067\u5bfe\u5fdc\u3057\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002<br \/>\nDockerfile\u306b\u305d\u306e\u307e\u307erun mysql\u305b\u305a\u306b\u4e0b\u8a18\u306e\u3088\u3046\u306b\u8a18\u8f09\u3059\u308b\u4e8b\u3067\u75c7\u72b6\u304c\u6cbb\u308a\u307e\u3057\u305f\u3002<br \/>\n# MySQL\u3092root\u3067\u5b9f\u884c\u3059\u308b\u8a2d\u5b9a\u306b\u66f8\u304d\u63db\u3048\u3066\u8d77\u52d5\u3059\u308b<br \/>\nRUN sed -e 's\/^ *user *= *mysql$\/user = root\/' -i \/etc\/mysql\/my.cnf<\/p>\n<p>\u8a73\u7d30\u306f\u4e0b\u8a18\u304c\u53c2\u8003\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\nhttps:\/\/qiita.com\/kazuma1989\/items\/3dae0d9dc78675162cae<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Contents1 \u6982\u89812 \u524d\u63d03 \u624b\u98064 \u906d\u9047\u3057\u305f\u30a8\u30e9\u30fc \u6982\u8981 Mac\u306eDocker\u4e0a\u3067DockerCompose\u3092\u4f7f\u7528\u3057\u3066MySQL\u74b0\u5883\u3092\u69cb\u7bc9\u3057\u3066\u52d5\u305b\u308b\u307e\u3067\u306e\u30e1\u30e2\u3067\u3059\u3002 \u4ee5\u524dPostgresSQL &#8230; <\/p>\n","protected":false},"author":1,"featured_media":1838,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[31],"tags":[],"_links":{"self":[{"href":"https:\/\/nobunobu1717.site\/index.php?rest_route=\/wp\/v2\/posts\/1833"}],"collection":[{"href":"https:\/\/nobunobu1717.site\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nobunobu1717.site\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nobunobu1717.site\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nobunobu1717.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1833"}],"version-history":[{"count":6,"href":"https:\/\/nobunobu1717.site\/index.php?rest_route=\/wp\/v2\/posts\/1833\/revisions"}],"predecessor-version":[{"id":1841,"href":"https:\/\/nobunobu1717.site\/index.php?rest_route=\/wp\/v2\/posts\/1833\/revisions\/1841"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nobunobu1717.site\/index.php?rest_route=\/wp\/v2\/media\/1838"}],"wp:attachment":[{"href":"https:\/\/nobunobu1717.site\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1833"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nobunobu1717.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1833"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nobunobu1717.site\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1833"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}