{"id":516,"date":"2019-01-20T00:00:00","date_gmt":"2019-01-19T15:00:00","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2019\/01\/20\/java11_springboot_docker"},"modified":"2022-10-26T10:14:03","modified_gmt":"2022-10-26T01:14:03","slug":"java11_springboot_docker","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2019\/01\/20\/java11_springboot_docker\/","title":{"rendered":"Java11+Spring Boot+Docker\u3067\u4f5c\u308bWeb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3"},"content":{"rendered":"

\u3053\u3093\u306b\u3061\u306f\u3001\u798f\u5713\u3067\u3059\u3002
\n\u51ac\u4f11\u307f\u4e2d\u306b\u500b\u4eba\u7684\u306b\u6b32\u3057\u3044\u3068\u611f\u3058\u3066\u3068\u3042\u308bWeb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u3063\u3066\u3044\u307e\u3057\u305f\u3002\u305d\u306e\u6642\u306b\u4f5c\u6210\u3057\u305f\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u69cb\u6210\u3092\u30e1\u30e2\u3068\u3057\u3066\u30d6\u30ed\u30b0\u306b\u6b8b\u3057\u3066\u304a\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002\u5b9f\u969b\u306b\u4f5c\u6210\u3057\u305f\u3082\u306e\u3068\u5185\u5bb9\u306f\u7570\u306a\u308a\u307e\u3059\u304c\u3001\u69cb\u6210\u3068\u3057\u3066\u306fWeb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304b\u3089\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u53d6\u5f97\u3057\u305f\u30c7\u30fc\u30bf\u306e\u4e00\u89a7\u3092\u753b\u9762\u306b\u8868\u793a\u3059\u308b\u3001\u3068\u3044\u3063\u305f\u30b7\u30f3\u30d7\u30eb\u306a\u3082\u306e\u3067\u3059\u3002\u4e00\u5ea6\u306b\u5168\u3066\u3092\u66f8\u304f\u3068\u82e5\u5e72\u9577\u304f\u306a\u308b\u306e\u3067\uff12\u56de\u306b\u5206\u5272\u3057\u3066\u63b2\u8f09\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n

\u4f7f\u7528\u3059\u308b\u8a00\u8a9e\u3084\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3001RDBMS\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002
IDE\u306fIntelliJ IDEA\u3092\u4f7f\u7528\u3057\u3066\u304a\u308a\u307e\u3059\u3002<\/p>\n

Java11\uff08OpenJDK\uff09
Spring Boot
MySQL5.7<\/p>\n

\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u96db\u5f62\u3092\u4f5c\u6210<\/h2>\n

\u307e\u305a\u306f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u96db\u5f62\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002
\nIntelliJ\u3067\u958b\u767a\u3057\u3066\u3044\u308b\u5834\u5408\u306f\u30e1\u30a4\u30f3\u30e1\u30cb\u30e5\u30fc\u304b\u3089\u30d5\u30a1\u30a4\u30eb | \u65b0\u898f | \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u9078\u629e\u3057\u3001Spring Initializr\u3092\u9078\u629e\u3057\u3066\u96db\u5f62\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<\/p>\n

\"\"
\n\u30d3\u30eb\u30c9\u30b7\u30b9\u30c6\u30e0\u306fGradle\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002
\n\"\"
\n\u3053\u3053\u3067\u5fc5\u8981\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u95a2\u9023\u3092\u9078\u629e\u3057\u307e\u3059\u3002
\nLombok\u306f\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3092\u4ed8\u3051\u308b\u3060\u3051\u3067getter, setter, toString, equals\u306a\u3069\u3092\u30b3\u30f3\u30d1\u30a4\u30eb\u6642\u306b\u81ea\u52d5\u751f\u6210\u3057\u3066\u304f\u308c\u308b\u4fbf\u5229\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002
\nThymeleaf\u306fSpring Boot\u3067\u4f7f\u7528\u304c\u63a8\u5968\u3055\u308c\u3066\u3044\u308b\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30a8\u30f3\u30b8\u30f3\u3067\u3059\u3002
\n\"\"
\n\u96db\u5f62\u4f5c\u6210\u5f8c\u306f\u3053\u306e\u3088\u3046\u306a\u5f62\u3068\u306a\u308a\u307e\u3059\u3002
\n\"\"<\/p>\n

Docker\u3067MySQL\u3092\u4f7f\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b<\/h2>\n

\u6b21\u306bDocker\u3067MySQL\u3092\u4f7f\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u74b0\u5883\u3092\u69cb\u7bc9\u3057\u3066\u3044\u304d\u307e\u3059\u3002
\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30eb\u30fc\u30c8\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306bdocker\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3068docker-compose.yml\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n

\u251c\u2500\u2500 build.gradle\n\u251c\u2500\u2500 docker\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 mysql\n\u2502\u00a0\u00a0     \u251c\u2500\u2500 Dockerfile\n\u2502\u00a0\u00a0     \u251c\u2500\u2500 conf.d\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u2514\u2500\u2500 my.cnf\n\u2502\u00a0\u00a0     \u2514\u2500\u2500 initdb.d\n\u2502\u00a0\u00a0         \u251c\u2500\u2500 1_schema.sql\n\u2502\u00a0\u00a0         \u2514\u2500\u2500 2_initdata.sql\n\u251c\u2500\u2500 docker-compose.yml<\/code><\/pre>\n

Dockerfile<\/p>\n

FROM mysql:5.7\nRUN touch \/var\/log\/mysql\/mysqld.log<\/code><\/pre>\n

my.cnf<\/p>\n

[mysqld]\ncharacter-set-server=utf8mb4\nexplicit-defaults-for-timestamp=1\ngeneral-log=1\ngeneral-log-file=\/var\/log\/mysql\/mysqld.log\n\n[client]\ndefault-character-set=utf8mb4<\/code><\/pre>\n

1_schema.sql<\/p>\n

CREATE TABLE customer (\n    id INT NOT NULL AUTO_INCREMENT,\n    first_name varchar(20),\n    last_name varchar(20),\n    PRIMARY KEY (id)\n);<\/code><\/pre>\n

2_initdata.sql<\/p>\n

INSERT INTO customer(first_name, last_name) VALUES('Tarou', 'Tanaka');\nINSERT INTO customer(first_name, last_name) VALUES('Jiro', 'Suzuki');<\/code><\/pre>\n

docker-compose.yml<\/p>\n

version: '2'\nservices:\n  dbserver:\n    build: .\/docker\/mysql\n    image: demo-db:0.0.1\n    restart: always\n    environment:\n      MYSQL_DATABASE: demo_db\n      MYSQL_USER: user\n      MYSQL_PASSWORD: password\n      MYSQL_ROOT_PASSWORD: rootpassword\n    ports:\n    - "3314:3306"\n    volumes:\n    - .\/docker\/mysql\/initdb.d:\/docker-entrypoint-initdb.d\n    - .\/docker\/mysql\/conf.d:\/etc\/mysql\/conf.d\n    - .\/log\/mysql:\/var\/log\/mysql\n\nvolumes:\n  mysql-db:\n    driver: local\n<\/code><\/pre>\n

\"\"<\/p>\n

MySQL\u30b3\u30f3\u30c6\u30ca\u3092\u7acb\u3061\u4e0a\u3052\u3066\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u307f\u308b<\/h2>\n

\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u30b5\u30fc\u30d3\u30b9\u306e\u30d3\u30eb\u30c9\u3068\u540c\u6642\u306b\u30b5\u30fc\u30d3\u30b9\u3092\u8d77\u52d5\u3057\u307e\u3059\u3002
\u5148\u7a0b\u4f5c\u6210\u3057\u305fsql\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u304c\u5b9f\u884c\u3055\u308c\u3066\u30c6\u30fc\u30d6\u30eb\u3068\u30c7\u30fc\u30bf\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002<\/p>\n

$ docker-compose up -d --build<\/code><\/p>\n

\u4ee5\u4e0b\u306e\u3088\u3046\u306bMySQL\u306e\u30b3\u30f3\u30c6\u30ca\u304c\u7acb\u3061\u4e0a\u304c\u308a\u307e\u3059\u3002<\/p>\n

$ docker ps\nCONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES\n5a24978ff730        demo-db:0.0.1       "docker-entrypoint.s\u2026"   2 minutes ago       Up 2 minutes        33060\/tcp, 0.0.0.0:3314->3306\/tcp   demo_dbserver_1<\/code><\/pre>\n

\u30b3\u30f3\u30c6\u30ca\u304c\u7acb\u3061\u4e0a\u304c\u3063\u305f\u3053\u3068\u3092\u78ba\u8a8d\u3057\u305f\u306e\u3067\u3001MySQL\u306b\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u30c6\u30fc\u30d6\u30eb\u304c\u4f5c\u6210\u3055\u308c\u3066\u3044\u308b\u304b\u78ba\u8a8d\u3057\u307e\u3059\u3002<\/p>\n

$ docker exec -it demo_dbserver_1 bash\nroot@5a24978ff730:\/# mysql -u user -ppassword demo_db\nmysql> select * from customer;\n+----+------------+-----------+\n| id | first_name | last_name |\n+----+------------+-----------+\n|  1 | Taro       | Tanaka    |\n|  2 | Jiro       | Suzuki    |\n+----+------------+-----------+\n1 row in set (0.00 sec)<\/code><\/pre>\n

\u30c6\u30fc\u30d6\u30eb\u304c\u4f5c\u6210\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3057\u305f\u3068\u3053\u308d\u3067\u4eca\u56de\u306f\u7d42\u308f\u308a\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002
\u4eca\u56de\u306fWeb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u96db\u5f62\u3092\u4f5c\u6210\u3057\u3066Docker\u3067MySQL\u30b3\u30f3\u30c6\u30ca\u3092\u7acb\u3061\u4e0a\u3052\u308b\u3068\u3053\u308d\u307e\u3067\u3092\u5b9f\u65bd\u3057\u307e\u3057\u305f\u3002<\/p>\n

\u6b21\u56de\u306f\u5b9f\u969b\u306bWeb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304b\u3089MySQL\u306b\u63a5\u7d9a\u3057\u3066\u53d6\u5f97\u3057\u305f\u30c7\u30fc\u30bf\u3092\u753b\u9762\u306b\u8868\u793a\u3059\u308b\u3068\u3053\u308d\u307e\u3067\u3092\u63b2\u8f09\u3057\u3088\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n

\u306a\u304a\u3001MMM\u306f\u4f1a\u793e\u3068\u3057\u3066\u3082Docker\u30b3\u30f3\u30c6\u30ca\u306b\u6ce8\u529b\u3057\u3066\u3044\u307e\u3059\u3002\u305c\u3072\u4ee5\u4e0b\u306e\u30da\u30fc\u30b8\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n

\u30fbDocker\u30b3\u30f3\u30c6\u30ca\u57fa\u76e4\uff08AWS Fargate\/Amazon ECS\uff09<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"

\u3053\u3093\u306b\u3061\u306f\u3001\u798f\u5713\u3067\u3059\u3002 \u51ac\u4f11\u307f\u4e2d\u306b\u500b\u4eba\u7684\u306b\u6b32\u3057\u3044\u3068\u611f\u3058\u3066\u3068\u3042\u308bWeb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u3063\u3066\u3044\u307e\u3057\u305f\u3002\u305d\u306e\u6642\u306b\u4f5c\u6210\u3057\u305f\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u69cb\u6210\u3092\u30e1\u30e2\u3068\u3057\u3066\u30d6\u30ed\u30b0\u306b\u6b8b\u3057\u3066\u304a\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002\u5b9f\u969b\u306b\u4f5c\u6210\u3057\u305f\u3082\u306e\u3068\u5185\u5bb9\u306f\u7570\u306a\u308a\u307e\u3059\u304c\u3001\u69cb\u6210\u3068\u3057\u3066\u306fWeb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304b\u3089\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u53d6\u5f97\u3057\u305f\u30c7\u30fc\u30bf\u306e\u4e00\u89a7\u3092\u753b\u9762\u306b\u8868\u793a\u3059\u308b\u3001\u3068\u3044\u3063\u305f\u30b7\u30f3\u30d7\u30eb\u306a\u3082\u306e\u3067\u3059\u3002\u4e00\u5ea6\u306b\u5168\u3066\u3092\u66f8\u304f\u3068\u82e5\u5e72\u9577\u304f\u306a\u308b\u306e\u3067\uff12\u56de\u306b\u5206\u5272 […]<\/p>\n","protected":false},"author":1,"featured_media":684,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[17],"tags":[73,266],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/516"}],"collection":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/comments?post=516"}],"version-history":[{"count":1,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/516\/revisions"}],"predecessor-version":[{"id":3372,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/516\/revisions\/3372"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/media?parent=516"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/categories?post=516"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/tags?post=516"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}