'docker compose phpmyadmin php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution

I am trying to set up a docker-pod with laravel, mariadb, nginx, redis and phpmyadmin. The laravel webspace works finde but if i switch to port 10081 like configured in the docker-compose.yml i am not able to login with the root account.

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

i already tried to configure a "my-network" which links all of the container, but if i understand docker right there is already a "defaul" network which does this. It didnt change the error message anyway.

here is my full docker-compose file

version: "3.8"
services:
  redis:
    image: redis:6.0-alpine
    expose:
      - "6380"

  db:
    image: mariadb:10.4
    ports:
      - "3307:3306"
    environment:
      MYSQL_USERNAME: root
      MYSQL_ROOT_PASSWORD: secret
      MYSQL_DATABASE: laravel
    volumes:
      - db-data:/var/lib/mysql

  nginx:
    image: nginx:1.19-alpine
    build:
      context: .
      dockerfile: ./docker/nginx.Dockerfile
    restart: always
    depends_on:
      - php
    ports:
      - "10080:80"
    networks:
      - default
    environment:
      VIRTUAL_HOST: cockpit.example.de
    volumes:
      - ./docker/nginx.conf:/etc/nginx/nginx.conf:ro
      - ./public:/app/public:ro

  php:
    build:
      target: dev
      context: .
      dockerfile: ./docker/php.Dockerfile
    working_dir: /app
    env_file: .env
    restart: always
    expose:
        - "9000"
    depends_on:
      - composer
      - redis
      - db
    volumes:
      - ./:/app
      - ./docker/www.conf:/usr/local/etc/php-fpm.d/www.conf:ro
    links:
      - db:mysql


  phpmyadmin:
    image: phpmyadmin/phpmyadmin:latest
    ports:
      - 10081:80
    restart: always
    environment:
      PMA_HOST : db
      MYSQL_USERNAME: root
      MYSQL_ROOT_PASSWORD: secret
    depends_on:
      - db
    #user: "109:115"
    links:
      - db:mysql
      
  node:
    image: node:12-alpine
    working_dir: /app
    volumes:
      - ./:/app
    command: sh -c "npm install && npm run watch"

  composer:
    image: composer:1.10
    working_dir: /app
    #environment:
      #SSH_AUTH_SOCK: /ssh-auth.sock
    volumes:
      - ./:/app
      #- "$SSH_AUTH_SOCK:/ssh-auth.sock"
      - /etc/passwd:/etc/passwd:ro
      - /etc/group:/etc/group:ro
    command: composer install --ignore-platform-reqs --no-scripts

volumes:
  db-data:


Solution 1:[1]

Make sure you have defined all attributes correctly for phpmyadmin container, in the current case there was the absence of -network definition

phpmyadmin:
  image: phpmyadmin/phpmyadmin:latest
  container_name: phpmyadmin
  restart: always
  ports:
    # 8080 is the host port and 80 is the docker port
     - 8080:80
  environment:
    - PMA_ARBITRARY:1
    - PMA_HOST:mysql
    - MYSQL_USERNAME:root
    - MYSQL_ROOT_PASSWORD:secret
  depends_on:
    - mysql
  networks:
  # define your network where all containers are connected to each other
    - laravel
  volumes:
  # define directory path where you shall store your persistent data and config 
  # files of phpmyadmin 
    - ./docker/phpmyadmin

Solution 2:[2]

Maybe your container cannot start because its volume contains incompatible data. It can happen if you downgrade the version of mysql or mariadb image.

You can resolve the problem if you remove the volume and import the database again. Maybe you have to create a backup first.

Solution 3:[3]

Got it

# We're using version 3.7 of the Docker Compose file format
version: "3.7"

# Define services/containers
services:
  # MySQL container
  mariadb:
    # Use mysql:8.0.19 image
    image: mariadb:10.4
    # Connect to "my-network" network, as defined below
    networks:
      - my-network
    # Pass a list of environment variables to the container
    environment:
      MYSQL_ROOT_PASSWORD: secret
    volumes:
      - db-data:/var/lib/mysql
    ports: 
      - "3307:3306"

  # phpMyAdmin container
  phpmyadmin:
    # Use phpmyadmin/phpmyadmin:5.0.2 image
    image: phpmyadmin/phpmyadmin
    # Connect to "my-network" network, as defined below
    networks:
      - my-network
    # Map port 8080 on the host to port 80 inside the container
    # Syntax is: "HOST_PORT:CONTAINER_PORT"
    ports:
      - "10081:80"
    # Pass a list of environment variables to the container
    volumes:
        - /sessions
    environment:
      PMA_HOST: mariadb
    # Wait for "mysql" container to start first 
    depends_on:
      - mariadb

  redis:
    image: redis:6.0-alpine
    expose:
      - "6380"

  nginx:
    image: nginx:1.19-alpine
    build:
      context: .
      dockerfile: ./docker/nginx.Dockerfile
    restart: always
    depends_on:
      - php
    ports:
      - "10080:80"
    networks:
      - my-network
    environment:
      VIRTUAL_HOST: cockpit.xyz.de
    volumes:
      - ./docker/nginx.conf:/etc/nginx/nginx.conf:ro
      - ./public:/app/public:ro

  php:
    build:
      target: dev
      context: .
      dockerfile: ./docker/php.Dockerfile
    working_dir: /app
    env_file: .env
    restart: always
    expose:
        - "9000"
    depends_on:
      - composer
      - redis
      - mariadb
    volumes:
      - ./:/app
      - ./docker/www.conf:/usr/local/etc/php-fpm.d/www.conf:ro
    links:
      - mariadb
    networks:
      - my-network
      
  node:
    image: node:12-alpine
    working_dir: /app
    volumes:
      - ./:/app
    command: sh -c "npm install && npm run watch"

  composer:
    image: composer:1.10
    working_dir: /app
    #environment:
      #SSH_AUTH_SOCK: /ssh-auth.sock
    volumes:
      - ./:/app
      #- "$SSH_AUTH_SOCK:/ssh-auth.sock"
      - /etc/passwd:/etc/passwd:ro
      - /etc/group:/etc/group:ro
    command: composer install --ignore-platform-reqs --no-scripts

# Define networks
networks:
  my-network:

volumes:
  db-data:

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MANSOOR KOCHY
Solution 2 Attila Kiss
Solution 3