前提・実現したいこと
MySQLをdockerで立ち上げようとしています。
init.sql
を読み込むようにdocker-compose.yml
に指定しました。
しかし、docker立ち上げ後にテーブルが作成されていませんでした。
発生している問題・エラーメッセージ
docker起動後、http://localhost:3000
にアクセスすると、以下のようなエラーがバックエンドサーバー(Golang)で発生します。
error
1api_1 | 2019/07/31 06:36:36 [Recovery] 2019/07/31 - 06:36:36 panic recovered: 2api_1 | GET /api/articles HTTP/1.1 3api_1 | Host: localhost:2345 4api_1 | Accept: application/json, text/plain, */* 5api_1 | Accept-Encoding: gzip, deflate, br 6api_1 | Accept-Language: en-US,en;q=0.9 7api_1 | Connection: keep-alive 8api_1 | Origin: http://localhost:3000 9api_1 | Referer: http://localhost:3000/ 10api_1 | User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36 11api_1 | 12api_1 | 13api_1 | Error 1146: Table 'article.articles' doesn't exist 14api_1 | /app/main.go:90 (0xb1c6d1) 15api_1 | main.func2: panic(err.Error()) 16api_1 | /go/src/github.com/gin-gonic/gin/context.go:147 (0x8f97c9) 17api_1 | (*Context).Next: c.handlers[c.index](c) 18api_1 | /go/src/github.com/gin-gonic/gin/recovery.go:83 (0x90d259) 19api_1 | RecoveryWithWriter.func1: c.Next() 20api_1 | /go/src/github.com/gin-gonic/gin/context.go:147 (0x8f97c9) 21api_1 | (*Context).Next: c.handlers[c.index](c) 22api_1 | /go/src/github.com/gin-gonic/gin/logger.go:240 (0x90c300) 23api_1 | LoggerWithConfig.func1: c.Next() 24api_1 | /go/src/github.com/gin-gonic/gin/context.go:147 (0x8f97c9) 25api_1 | (*Context).Next: c.handlers[c.index](c) 26api_1 | /go/src/github.com/gin-gonic/gin/gin.go:391 (0x9036c9) 27api_1 | (*Engine).handleHTTPRequest: c.Next() 28api_1 | /go/src/github.com/gin-gonic/gin/gin.go:352 (0x902dbd) 29api_1 | (*Engine).ServeHTTP: engine.handleHTTPRequest(c) 30api_1 | /usr/local/go/src/net/http/server.go:2774 (0x6dcc77) 31api_1 | serverHandler.ServeHTTP: handler.ServeHTTP(rw, req) 32api_1 | /usr/local/go/src/net/http/server.go:1878 (0x6d8860) 33api_1 | (*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req) 34api_1 | /usr/local/go/src/runtime/asm_amd64.s:1337 (0x45a090) 35api_1 | goexit: BYTE $0x90 // NOP 36api_1 | 37api_1 | [GIN] 2019/07/31 - 06:36:36 | 500 | 84.4365ms | 172.18.0.1 | GET /api/articles 38^CGracefully stopping... (press Ctrl+C again to force)
該当のソースコード
file
1//フォルダ構成 2article 3 ├ db 4 │ └ init.sql 5 │ 6 └ docker-compose.yml
yml
1//docker-compose.yml 2version: '3' 3services: 4 db: 5 image: mysql 6 ports: 7 - '3306:3306' 8 environment: 9 MYSQL_ROOT_PASSWORD: root 10 MYSQL_DATABASE: article 11 MYSQL_USER: docker 12 MYSQL_PASSWORD: docker 13 volumes: 14 - ./db:/docker-entrypoint-initdb.d
mysql
1//init.sql 2CREATE DATABASE IF NOT EXISTS article; 3use article; 4CREATE TABLE IF NOT EXISTS `articles` (`id` int NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT "ID",uuid varchar(36), `title` VARCHAR(100) NOT NULL COMMENT "タイトル",`content` TEXT NOT NULL COMMENT "本文" ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 5create table IF NOT EXISTS images (id int AUTO_INCREMENT NOT NULL PRIMARY KEY, article_uuid varchar(36), image_name varchar(50));
補足情報(FW/ツールのバージョンなど)
フロント:React/axios
サーバー:Golang/gin
DB: mysql
その他:nginx
以上お手数ですが、ご教授いただけると幸いです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。