skip to Main Content

I have the following docker-compose file.

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: {}

My problem Is that when I try to login with phpmyadmin I get the following error:

mysqli::real_connect(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution

And also

mysqli::real_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution

Is there something I’m missing?

2

Answers


  1.     networks:
          - webnet
    

    add webnet network to phpmyadmin service

    Login or Signup to reply.
  2. There are more options to solve the connection.

    1. Add phpmyadmin container to webnet network as Def Soudani suggests. The YML example provided overrides the default network. Since the phpMyAdmin is lacking the network config, it won’t be on the webnet docker network by default.
    2. Remove all networks related config from the YML. Since compose already creates a default network (docs) for the containers within one YML file.
    3. Use the PMA_ARBITRARY=1 (docs )which allows you to enter a database server hostname on login form.

    Example of my YML setup with custom bridge networking:

    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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search