我的Docker(v.2)docker-compose.yml
文件有2个Ubuntu图像和2个MariaDB图像:
app:
container_name: app
image:php-apache-dev:ubuntu-16.04
links:
- mysql
depends_on:
- mysql
ports:
- '8443:443'
volumes:
- .:/app
environment:
docker: 'true'
PHP_DEBUGGER: 'xdebug'
WEB_DOCUMENT_ROOT: '/app/public'
WEB_NO_CACHE_PATTERN: '\.(.*)$$'
working_dir: '/app'
CONF_FILE: 'conf/local/develop.php'
test:
container_name: test
image:php-apache-dev:ubuntu-16.04
links:
- mysql_test
depends_on:
- mysql_test
ports:
- '8444:443'
volumes:
- .:/app
environment:
docker: 'true'
WEB_DOCUMENT_ROOT: '/app/public'
WEB_NO_CACHE_PATTERN: '\.(.*)$$'
working_dir: '/app'
CONF_FILE: 'conf/local/test.php'
mysql:
image: mariadb:latest
ports:
- '3306:3306'
environment:
MYSQL_ROOT_PASSWORD: 'dev'
MYSQL_DATABASE: 'dev'
MYSQL_USER: 'dev'
MYSQL_PASSWORD: 'dev'
mysql_test:
image: mariadb:latest
ports:
- '3307:3306'
environment:
MYSQL_ROOT_PASSWORD: 'dev'
MYSQL_DATABASE: 'dev_test'
MYSQL_USER: 'dev'
MYSQL_PASSWORD: 'dev'
一个用于开发,一个用于测试。当我访问第一个(localhost:4443
)时,它可以工作。当我访问第二个(localhost:4444
)时,我可以查看该网站,但它拒绝访问该用户:
拒绝访问用户' dev' @'%'到数据库' dev_test'
第二个站点的我的配置设置为访问第二个MySQL端口/用户:
'db_port' => env('DB_PORT', '3307'),
'db_name' => env('DB_NAME', 'dev_test'),
我尝试了this question的答案但没有成功。如果我docker exec bash
进入测试数据库图像并运行SHOW GRANTS FOR dev
,则会显示:
GRANT ALL PRIVILEGES ON `dev_test`.* TO 'dev'@'%'
答案 0 :(得分:1)
您可能忘记在第二个站点中使用正确的MySQL主机。