Docker / phpmyadmin:无法连接到

eoigrqb6  于 2022-11-23  发布在  PHP
关注(0)|答案(2)|浏览(165)

我有下面的docker-compose文件。

version: "3.7"
services:
  main:
    container_name: buspack_main
    build:
      context: .
      target: development
    volumes:
      - .:/usr/src/app
      - /usr/src/app/node_modules
    ports:
      - ${API_PORT}:${API_PORT}
    command: bash -c "npm install --save && npm run start:dev"
    env_file:
      - .env
    networks:
      - webnet
    depends_on:
      - db
    links:
      - db
    restart: always

  db:
    container_name: buspack_db
    image: mysql:5.7.33
    networks:
      - webnet
    environment:
      MYSQL_ROOT_PASSWORD: 123456
      MYSQL_DATABASE: "backendnest"
    ports:
      - 23306:3306
    restart: always
    volumes:
      - ./db:/var/lib/mysql:rw

  phpmyadmin:
    container_name: buspack_phpmyadmin
    image: phpmyadmin/phpmyadmin
    depends_on:
      - db
    restart: always
    ports:
      - '8030:80'
    environment:
      PMA_HOST: buspack_db
      MYSQL_ROOT_PASSWORD: 123456
networks:
  webnet:
volumes:
  db: {}

我的问题是,当我尝试登录phpmyadmin我得到以下错误:
如果您有任何问题,真实的与我们联系。php_网络_获取地址:获取地址信息失败:名称解析暂时失败
还有
如果您有任何问题,请与我们联系。(HY 000/2002)的规定:php_网络_获取地址:获取地址信息失败:名称解析暂时失败
我是不是错过了什么?

kxe2p93d

kxe2p93d1#

networks:
      - webnet

添加webnet网络到phpmyadmin服务

u5rb5r59

u5rb5r592#

有更多的选项来解决连接。
1.按照Def Soudani的建议将phpmyadmin容器添加到webnet网络。提供的YML示例覆盖了默认网络。由于phpMyAdmin缺少网络配置,因此默认情况下它不会在webnet docker网络上。
1.从YML中删除所有与networks相关的配置。因为compose已经为一个YML文件中的容器创建了默认网络(docs)。
1.使用PMA_ARBITRARY=1docs),它允许您在登录表单上输入数据库服务器主机名.
使用自定义网桥网络的YML设置示例:

version: '3.8'

services:
  mysql:
    image: mysql:5.7
    container_name: myapp-mysql-db
    restart: unless-stopped
    ports:
      - "3306:3306"
    environment:
      MYSQL_DATABASE: ${DB_DATABASE}
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
      MYSQL_PASSWORD: ${DB_PASSWORD}
      MYSQL_USER: ${DB_USERNAME}
    volumes:
      - ./database/dbdata:/var/lib/mysql
    networks:
      - myapp-network

  phpmyadmin:
    image: phpmyadmin:latest
    container_name: phpmyadmin
    ports:
      # 8080 is the host port and 80 is the docker port
      - 8080:80
    environment:
      PMA_HOST: mysql
      UPLOAD_LIMIT: 20M
      MYSQL_USERNAME: ${DB_USERNAME}
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
    restart: unless-stopped
    networks:
      # define your network where all containers are connected to each other
      - myapp-network

networks:
  myapp-network:
    driver: bridge

相关问题