是否可以使用docker在phpMyAdmin中拥有多个默认mysql服务器

发布于 2025-01-08 23:58:30 字数 1642 浏览 1 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

十秒萌定你 2025-01-15 23:58:30

您是否尝试过将环境变量 PMA_HOST 更改为 PMA_HOSTS

phpMyAdmin 选择服务器的屏幕截图

官方 phpMyAdmin Docker 镜像

Did you been tried to change the environment variable PMA_HOST to PMA_HOSTS?

Screenshot of phpMyAdmin select server

Official phpMyAdmin Docker image

债姬 2025-01-15 23:58:30

是的!!!您可以在 docker 中使用单个 PhpMyAdmin 实例连接多个数据库。

请在此处找到示例:

version: "3"
networks:
  sample_network:
services:
  db-1:
    image: mariadb:10.5.8
    container_name: db-1
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: notSecureWay
      MYSQL_ROOT_USER: root
      MYSQL_DATABASE: db-1
      MYSQL_PASSWORD: notSecureWay
    networks:
      - sample_network
#    ports:
#      - 8087:3306
    volumes:
      - db1_data:/var/lib/mysql

  db-2:
    image: mariadb:10.5.8
    container_name: db-2
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: notSecureWay
      MYSQL_ROOT_USER: root
      MYSQL_DATABASE: db-2
      MYSQL_PASSWORD: notSecureWay
    networks:
      - sample_network
#    ports:
#      - 8088:3306
    volumes:
      - db2_data:/var/lib/mysql
      
  phpmyadmin:
    image: phpmyadmin
    container_name: phpmyadmin
    links:
      - db-1
      - db2
    environment:
      PMA_HOSTS: dv-1,db-2
      PMA_PORT: 3306
      PMA_ARBITRARY: 1
    restart: always
    networks:
      - sample_network
    ports:
      - 8090:80


volumes:
  db1_data:
  db2_data:

使用 http://localhost:8090/ 在浏览器中启动 phpMyAdmin 应用程序
您可以在 phpMyAdmin 应用程序的登录屏幕中选择数据库。

Yes!!! You can connect multiple DB with a single PhpMyAdmin instance in docker.

Please find a sample here:

version: "3"
networks:
  sample_network:
services:
  db-1:
    image: mariadb:10.5.8
    container_name: db-1
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: notSecureWay
      MYSQL_ROOT_USER: root
      MYSQL_DATABASE: db-1
      MYSQL_PASSWORD: notSecureWay
    networks:
      - sample_network
#    ports:
#      - 8087:3306
    volumes:
      - db1_data:/var/lib/mysql

  db-2:
    image: mariadb:10.5.8
    container_name: db-2
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: notSecureWay
      MYSQL_ROOT_USER: root
      MYSQL_DATABASE: db-2
      MYSQL_PASSWORD: notSecureWay
    networks:
      - sample_network
#    ports:
#      - 8088:3306
    volumes:
      - db2_data:/var/lib/mysql
      
  phpmyadmin:
    image: phpmyadmin
    container_name: phpmyadmin
    links:
      - db-1
      - db2
    environment:
      PMA_HOSTS: dv-1,db-2
      PMA_PORT: 3306
      PMA_ARBITRARY: 1
    restart: always
    networks:
      - sample_network
    ports:
      - 8090:80


volumes:
  db1_data:
  db2_data:

Start your phpMyAdmin app in browser using http://localhost:8090/
You can select the database in the login screen of your phpMyAdmin app.

〆一缕阳光ご 2025-01-15 23:58:30

除了 PMA_HOSTS 之外,还有自定义配置可以使用。创建一个名为 config.user.inc.php 的文件并将内容放在下面。

<?php

#config.user.inc.php file

$cfg['Servers'] = [
    1 => [ #For MySQL instance inside docker compose
        'auth_type' => 'config',
        'host' => 'container_name',
        'user' => 'USER',
        'password' => 'PASSWORD',
    ],
    2 => [ # for remote connection
        'auth_type' => 'config',
        'host' => 'REMOTE_HOST_IP',
        'user' => 'USER',
        'password' => 'PASSWORD'
    ],
    # Add other connections if needed.
];

然后,添加一个新卷 localPath/config.user.inc.php:/etc/phpmyadmin/config.user.inc.php

Besides PMA_HOSTS also customized configuration can be used. Create a file called config.user.inc.php and put the content below.

<?php

#config.user.inc.php file

$cfg['Servers'] = [
    1 => [ #For MySQL instance inside docker compose
        'auth_type' => 'config',
        'host' => 'container_name',
        'user' => 'USER',
        'password' => 'PASSWORD',
    ],
    2 => [ # for remote connection
        'auth_type' => 'config',
        'host' => 'REMOTE_HOST_IP',
        'user' => 'USER',
        'password' => 'PASSWORD'
    ],
    # Add other connections if needed.
];

Then, add a new volume localPath/config.user.inc.php:/etc/phpmyadmin/config.user.inc.php

魔法少女 2025-01-15 23:58:30

请看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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文