是否可以使用docker在phpMyAdmin中拥有多个默认mysql服务器
我正在尝试使用 Docker 与两台 MySQL 服务器和一台 phpMyAdmin 服务器构建环境,以便在开发过程中轻松分析数据。 我的 docker-compose.yml 看起来像这样。
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
我想知道是否有任何构建方式来存档此内容。
I'm trying to build enviroment using Docker with two MySQL servers, and one phpMyAdmin server to easily analyze data during development.
My docker-compose.yml looks like this.
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
I was wondering is there any build in way to archive this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您是否尝试过将环境变量
PMA_HOST
更改为PMA_HOSTS
?官方 phpMyAdmin Docker 镜像
Did you been tried to change the environment variable
PMA_HOST
toPMA_HOSTS
?Official phpMyAdmin Docker image
是的!!!您可以在 docker 中使用单个 PhpMyAdmin 实例连接多个数据库。
请在此处找到示例:
使用 http://localhost:8090/ 在浏览器中启动 phpMyAdmin 应用程序
您可以在 phpMyAdmin 应用程序的登录屏幕中选择数据库。
Yes!!! You can connect multiple DB with a single PhpMyAdmin instance in docker.
Please find a sample here:
Start your phpMyAdmin app in browser using http://localhost:8090/
You can select the database in the login screen of your phpMyAdmin app.
除了
PMA_HOSTS
之外,还有自定义配置可以使用。创建一个名为 config.user.inc.php 的文件并将内容放在下面。然后,添加一个新卷
localPath/config.user.inc.php:/etc/phpmyadmin/config.user.inc.php
Besides
PMA_HOSTS
also customized configuration can be used. Create a file calledconfig.user.inc.php
and put the content below.Then, add a new volume
localPath/config.user.inc.php:/etc/phpmyadmin/config.user.inc.php
请看phpMyAdmin文档,有环境变量要做这。
PMA_HOSTS 用于设置 phpMyAdmin 容器,并在下拉列表中提供可用服务器列表。
删除 PMA_HOST 并替换为 PMA_HOSTS(以逗号分隔的主机列表)。
如果您的所有主机都使用相同的端口,您可以保留 PMA_PORT。
但如果您有多个端口,请将 PMA_PORT 替换为 PMA_PORTS,以便您可以提供以逗号分隔的端口列表。
Please look at phpMyAdmin documentation, there are environment variables to do this.
There is PMA_HOSTS to setup phpMyAdmin container with a list of servers available in a dropdown.
Remove PMA_HOST and replace with PMA_HOSTS with a comma separated list of hosts.
If all your hosts use the same port, you can keep PMA_PORT.
But if you have multiple ports then replace PMA_PORT with PMA_PORTS so you can provide a comma separated list of ports.