API 502 error as soon as I added mysql database credentials

Hi there,

Until now I had vikunja running with a sqlite Database. But since this is to unsecure for me (loosing data by deleting the file etc.) I wanted to switch to mysql.

So I added the following lines to my docker compose file:

      VIKUNJA_DATABASE_TYPE: mysql
      VIKUNJA_DATABASE_HOST: 1.1.1.1
      VIKUNJA_DATABASE_DATABASE: vikunja
      VIKUNJA_DATABASE_USER: vikunja
      VIKUNJA_DATABASE_PASSWORD: vikunja

So my compose file now looks like this:

version: '3.8'
services:
  api:
    image: vikunja/api
    container_name: API
    restart: always
    volumes:
      - ~/docker/vikunja/files:/app/vikunja/files
    environment:
      VIKUNJA_SERVICE_ENABLECALDAV: 'false'
      VIKUNJA_SERVICE_ENABLEREGISTRATION: 'false'
      VIKUNJA_SERVICE_ENABLEUSERDELETION: 'false'
      VIKUNJA_SERVICE_TIMEZONE: 'Europe/Berlin'
      VIKUNJA_DATABASE_TYPE: mysql
      VIKUNJA_DATABASE_HOST: 1.1.1.1
      VIKUNJA_DATABASE_DATABASE: vikunja
      VIKUNJA_DATABASE_USER: vikunja
      VIKUNJA_DATABASE_PASSWORD: vikunja
  frontend:
    image: vikunja/frontend
    container_name: Frontend
    restart: always
  proxy:
    image: nginx
    container_name: Proxy
    restart: always
    ports:
      - 80:80/tcp
    volumes:
      - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on:
      - api
      - frontend

The DB is hosted on an external server, so I entered my IP address for the host env (like VIKUNJA_DATABASE_HOST: 1.1.1.1 (of course I changed this to my servers IP)

When I then start the container, the API endpoint is not available anymore. I always get a 502 Bad Gateway, when I try to access <ip>/api/v1/info and login/register is also not possible anymore.

When I remove the db lines again, everything works fine again.
I also checked the API container logs, and this is the only content:

usermod: no changes
2021/09/29 13:10:21 Config File "config" Not Found in "[/app/vikunja /etc/vikunja /app/vikunja/.config/vikunja]"
2021/09/29 13:10:21 Using default config.

Do I miss something within the config? What can I do to fix this?

Thanks!

Hi :wave:

There should be other lines like

2021-09-29T21:14:03.532999671+02:00: INFO	▶ cmd/func2 04a Vikunja version v0.18.1+22-2ab27c72f2
⇨ http server started on [::]:3456

If these are missing that could indicate a problem somewhere. Can you verify the container can reach the mysql container?

The 502 seems to indicate the proxy cannot reach the api container - can you verify that as well? It should be running and reachable under the path you have in your nginx.conf file.

1 Like

Hi,

A firewall rule bocked the connection to the database server :roll_eyes:
But thanks for the help! :slightly_smiling_face:

1 Like