How can I connect a adminer docker container with a mariadb docker container?

2.9k Views Asked by At

I was trying to create a PHP development environment with PHP, MariaDB, and a tutorial suggested to use Adminer for database management. So I generate my docker-compose.yml file like this:

version : '3.1'

services:
  php:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - 80:80
    volumes:
      - ./src:/var/www/html/
  db:
    image: mariadb
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example
    volumes:
      - ./mariadb-data:/var/lib/mysql
  adminer:
    image: adminer
    environment:
      ADMINER_DEFAULT_SERVER: db
    restart: always
    ports:
      - 8080:8080

But when I set the volumes for MariaDB, I got an error in the Adminer login page. When I don't set them it seems to work well.

enter image description here

1

There are 1 best solutions below

1
On
version : '3.1'

services:
  php:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - 80:80
    volumes:
      - ./src:/var/www/html/
  db:
    image: mariadb
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example
    volumes:
      - ./mariadb-data:/var/lib/mysql
  adminer:
    image: adminer
    environment:
      ADMINER_DEFAULT_SERVER: db
    restart: always
    ports:
      - 8080:8080
    links:
        - php
        - db