Docker-compose with traefik, nextcloud and mariadb

i have created a docker-compose for my container traefik and it is working.

version: "3"
services:
  traefik:
    image: traefik
    command: --web --docker --docker.domain=docker.localhost --logLevel=DEBUG
    ports:
      - "80:80"
      - "8080:8080"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /dev/null:/traefik.toml
    networks:
      - webgateway

networks:
  webgateway:
    driver: bridge

And i tied to create a docker-compose for nextcloud and mariadb:

version: '3'
services:
  db:
    image: mariadb
    container_name: maria-db
    restart: always
    volumes:
      - /var/lib/mariadb
    environment:
      - MYSQL_ROOT_PASSWORD=nextcloud
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_PASSWORD=nextcloud
    networks:
     - traefik

  app:
    depends_on:
      - db
    image: nextcloud
    volumes:
      - /var/www/html
    expose:
      - "80"
    labels:
      - "traefik.docker.network=traefik"
      - "traefik.backend=nextcloud"
      - "traefik.frontend.rule=Host:nextcloud.edraniin.ml"
      - "traefik.port=80"
    networks:
      - traefik

networks:
  traefik:
    external:
      name: traefik_webgateway

it is also working but i have a problem with mariadb.
When i enter the informations for finish the installation i have this error:

Error while trying to create admin user: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for user 'nextcloud'@'172.22.0.3' (using password: YES) 

i see there is a problem with my access but i don’t what to do.
thank’s for your help

can you try, instead of using the ip for the mysql container, use the name, “db” or “maria-db”

i have already tried “db” and “maria-db”
it doesn’t work

Hi @edraniin ,
I had kind of the same issue…

When you do docker-compose up for the first time you have to give some minutes(from 5 to 10…) to mariadb’s docker.

I hope this helps… if it is still an issue.