我无法想出这个。下面是我的docker撰写文件。这是一个docker swarm,但都在一个主机上(只是测试设置)。我正在尝试将应用程序用户添加到mysql,以便Web容器可以访问db容器的mysql服务器。我不想使用通用主机通配符,因为db容器的mysql端口将向全世界开放。有没有办法自动完成?我尝试使用'web'作为主机,但我始终从'10 .0.0.x'错误中获取访问权限。
谢谢!
更新sql:
UPDATE mysql.user SET host = 'web' where user = 'app';
FLUSH PRIVILEGES;
连接错误:
Access denied for user 'app'@'10.0.1.4' (using password: YES)
搬运工-撰写:
version: "3.4"
services:
web:
image: app:latest
ports:
- 4000:80
# networks:
# - appnet
volumes:
- uploads:/app/uploads
secrets:
- dbapp
- mailkey
- sessionsecret
deploy:
replicas: 1
restart_policy:
condition: on-failure
delay: 1s
max_attempts: 10
redis:
image: redis:alpine
# networks:
# - appnet
db:
image: mysql:5.7
# networks:
# - appnet
secrets:
- dbroot
- dbapp
environment:
MYSQL_DATABASE: "app"
MYSQL_USER: "app"
MYSQL_ROOT_PASSWORD_FILE: /run/secrets/dbroot
MYSQL_PASSWORD_FILE: /run/secrets/dbapp
volumes:
- db:/var/lib/mysql
- ./scripts:/docker-entrypoint-initdb.d
secrets:
dbroot:
external: true
dbapp:
external: true
sessionsecret:
external: true
mailkey:
external: true
volumes:
uploads:
db:
# networks:
# - appnet