我想创建多个数据库服务,然后使用docker-compose在单个phpmyadmin服务中查看数据库。
docker-compose文件在下面
version: '3.9'
services:
dbone:
image: mysql:latest
restart: always
container_name: dbone
ports:
- "8080:3306"
environment:
- MYSQL_HOST=mysql
- MYSQL_DATABASE=sakila
- MYSQL_USER=user
- MYSQL_PASSWORD=test
- MYSQL_ROOT_PASSWORD=test
- TZ=Africa/Lagos
volumes:
- ./docker/data/db/mysql/dump/2-create-schema.sql:/docker-entrypoint-initdb.d/2.sql
- persistent_1:/var/lib/mysql
command: ["--character-set-server=utf8mb4", "--collation-server=utf8mb4_general_ci", "--skip-character-set-client-handshake", "--default-authentication-plugin=caching_sha2_password"]
dbtwo:
image: mysql:latest
restart: always
container_name: dbtwo
ports:
- "8090:3306"
environment:
- MYSQL_HOST=mysql
- MYSQL_DATABASE=mysql_json_db
- MYSQL_USER=user
- MYSQL_PASSWORD=test
- MYSQL_ROOT_PASSWORD=test
- TZ=Africa/Lagos
volumes:
- ./docker/data/db/mysql/dump/mysql_json_db.sql:/docker-entrypoint-initdb.d/1.sql
- persistent_2:/var/lib/mysql
command: ["--character-set-server=utf8mb4", "--collation-server=utf8mb4_general_ci", "--skip-character-set-client-handshake", "--default-authentication-plugin=caching_sha2_password"]
phpmyadmin:
image: phpmyadmin:latest
restart: always
container_name: phpmyadmin
depends_on:
- done
- dbtwo
ports:
- "8070:80"
environment:
- MAX_EXECUTION_TIME=0
- PMA_HOST=mysql
- PMA_ARBITRARY=1
volumes:
persistent_1:
persistent_2:
字符串
如上所述,dbone和dbtwo是我想让phpmyadmin服务可用的数据库服务。为了做到这一点,我分别将mysql设置为dbone和dbtwo的MYSQL_HOST主机名,并将mysql设置为phpmyadmin服务的PMA_HOST主机名。
我觉得dbone和dbtwo这样的服务名应该分别是两个容器的MYSQL_HOST名称。但是如果我分别为dbone和dbtwo容器设置MYSQL_HOST=dbone和MYSQL_HOST=dbtwo,我发现很难为phpmyadmin容器设置PMA_HOST。
我的docker-compose文件已经使用以下命令运行
docker-compose up --build
型
我尝试访问localhost:8070,打开phpmyadmin,但尝试使用用户名登录:用户和密码:测试,失败并显示以下内容:
Cannot log in to the MySQL server
mysqli::real_connect(): php_network_getaddresses: getaddrinfo for mysql failed: Temporary failure in name resolution
mysqli::real_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo for mysql failed: Temporary failure in name resolution
型
请帮助我解决这个问题。
1条答案
按热度按时间7dl7o3gd1#
它现在可以通过以下更新工作
字符串