多个默认的MySQL服务器在Docker的phpMyAdmin中是否可行?
P粉718730956
2023-08-25 21:56:14
<p>我正在尝试使用Docker构建环境,其中包括两个MySQL服务器和一个phpMyAdmin服务器,以便在开发过程中轻松分析数据。
我的docker-compose.yml文件如下。</p>
<pre class="brush:php;toolbar:false;">version: "3.9"
services:
database1:
container_name: Database1
image: mysql:8.0.28
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_DATABASE: database1
MYSQL_ROOT_PASSWORD: somepassword
MYSQL_USER: databaseuser1
MYSQL_PASSWORD: databaseuser1
ports:
- "3306:3306"
volumes:
- database-volume:/var/lib/mysql
networks:
- my_network
database2:
container_name: Database2
image: mysql:8.0.28
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_DATABASE: database2
MYSQL_ROOT_PASSWORD: somepassword
MYSQL_USER: databaseuser2
MYSQL_PASSWORD: databaseuser2
ports:
- "3307:3306"
volumes:
- second-database-volume:/var/lib/mysql
networks:
- my_network
phpmyadmin:
container_name: PhpMyAdmin
image: phpmyadmin/phpmyadmin:5.1.3
restart: always
depends_on:
- database1
- database2
environment:
PMA_HOST: database1, database2
PMA_PORT: 3306, 3307
PMA_USER: databaseuser1, databaseuser2
PMA_PASSWORD: databaseuser1, databaseuser2
ports:
- "8080:80"
networks:
- my_network
volumes:
database-volume:
second-database-volume:
networks:
my_network:
driver: bridge</pre>
<p>我想知道是否有内置的方法来实现这个目标。</p>
你是否尝试过将环境变量
PMA_HOST
更改为PMA_HOSTS
?官方phpMyAdmin Docker镜像