我正在使用 Docker、docker-compose、MySQL 和 Go 构建一个应用程序。
当我尝试测试一个端点时,我收到错误Table 'test_db.colors' doesn't exist。
似乎 sql 转储没有正确导入。
但是我可以连接数据库,至少没有错误,这是在同一个.sql文件中创建的。
当我启动应用程序时,终端显示:
golang_app | 2020/06/20 21:48:04 docker:docker@tcp(db_mysql:3306)/test_db
golang_app | 2020/06/20 21:48:04 DB Connected
在我向端点发出请求后,我得到:
2020/06/20 22:05:00 File: handlers.go Function: main.testDBHandler Line: 26 Error 1146: Table 'test_db.colors' doesn't exist
文件结构为:
./
|_app/
|_docker-compose.yml
|_Go/
|_*.go
|_Dockerfile
|_MySQL/
|_Dockerfile
|_.env
|_sql-scripts/
|_test.sql
文件的内容如下所示:
码头工人-compose.yml
version: '3'
services:
fullstack-mysql:
container_name: db_mysql
build:
context: ./MySQL
ports:
- 3306:3306
volumes:
- database_mysql:/var/lib/mysql
- mysql-log:/var/log/mysql
- mysql-conf:/etc/mysql/conf.d
- ./MySQL/sql-scripts:/docker-entrypoint-initdb.d
networks:
- fullstack
app:
container_name: golang_app
env_file:
- ./Go/.env
build:
context: ./Go
ports:
- 9000:9000
restart: unless-stopped
volumes:
- api:/usr/src/app/
depends_on:
- fullstack-mysql
networks:
- fullstack
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin_container
depends_on:
- fullstack-mysql
environment:
- PMA_HOST=fullstack-mysql #Note the "mysql". Must be the name of the what you used as the mysql service.
- PMA_USER=root
- PMA_PORT=3306
- PMA_PASSWORD=root
- PMA_ARBITRARY=1
ports:
- 9095:80
restart: always
networks:
- fullstack
links:
- fullstack-mysql
volumes:
api:
database_mysql:
mysql-log:
driver: local
mysql-conf:
driver: local
networks:
fullstack:
driver: bridge
应用程序/MySQL/Dockerfile
四季花海
守候你守候我
相关分类