Home > database >  Docker compose in Azure: Can't connect to database
Docker compose in Azure: Can't connect to database

Time:11-24

I'm trying to get SteVe OCPP server to run in an Azure Container Instance. But the web application won't connect to the database when running docker-compose up in an Azure ACI context. It runs just fine locally.

Here's the docker compose file:

version: "3.0"

volumes:
  db-data:
    external: false

services:
  db:
    image: mariadb:10.4
    ports:
      - 3306:3306
    environment:
      MYSQL_RANDOM_ROOT_PASSWORD: "yes"
      MYSQL_DATABASE: stevedb
      MYSQL_USER: steve
      MYSQL_PASSWORD: changeme
  web:
    image: rainmakers/steve:latest
    links:
      - "db:mariadb"
    ports:
      - 8180:8180
      - 8443:8443
    depends_on:
      - db

This is the only thing I'm getting in the web service logs:

2021/11/23 13:20:57 Waiting for: tcp://mariadb:3306
2021/11/23 13:20:57 Problem with dial: dial tcp: lookup mariadb on 168.63.129.16:53: no such host. Sleeping 1s
2021/11/23 13:20:58 Problem with dial: dial tcp: lookup mariadb on 168.63.129.16:53: no such host. Sleeping 1s
2021/11/23 13:20:59 Problem with dial: dial tcp: lookup mariadb on 168.63.129.16:53: no such host. Sleeping 1s
2021/11/23 13:21:00 Problem with dial: dial tcp: lookup mariadb on 168.63.129.16:53: no such host. Sleeping 1s
2021/11/23 13:21:01 Problem with dial: dial tcp: lookup mariadb on 168.63.129.16:53: no such host. Sleeping 1s
2021/11/23 13:21:02 Problem with dial: dial tcp: lookup mariadb on 168.63.129.16:53: no such host. Sleeping 1s
2021/11/23 13:21:03 Problem with dial: dial tcp: lookup mariadb on 168.63.129.16:53: no such host. Sleeping 1s

This continues for a minute, before the service terminates.

Any idea how to proceed here?

CodePudding user response:

I geuss you should connect with http://db:3306 instead of mariadb:3306.

By default Docker Compose version 3 uses the service name as hostname of inter-container networking.

  • Related