Docker with MySQL

mattb3 days ago

I have tried and tried but cannot get the Docke image to utilise MySQL. It appears to fail and fall back silently to use the internal DB. Here is my Docker compose file. Please comment if you can see an issue with it:

services:
  mysql:
    image: mysql:8.0
    container_name: traccar-mysql-local
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 123456
      MYSQL_DATABASE: traccar
      MYSQL_USER: traccar
      MYSQL_PASSWORD: 123456
    volumes:
      - mysql-data:/var/lib/mysql
    command: --default-authentication-plugin=mysql_native_password

  traccar:
    image: traccar/traccar:latest
    container_name: traccar-app-local
    restart: always
    ports:
      - "8082:8082"
      - "5055:5055"
      - "5055:5055/udp"
    environment:
      DATABASE_URL: "jdbc:mysql://mysql:3306/traccar?allowPublicKeyRetrieval=true&useSSL=false"
      DATABASE_USER: "traccar"
      DATABASE_PASSWORD: "123456"
      DATABASE_DRIVER: "com.mysql.jdbc.Driver"
    depends_on:
      - mysql

volumes:
  mysql-data:
Anton Tananaev3 days ago

How did you enable Traccar to use env variables?

Turbovix2 days ago

Dear, you do not need these environment variables here when creating the Traccar container, you must pass them in the traccar.xml configuration file.

Turbovix2 days ago

If you visit: https://hub.docker.com/r/traccar/traccar
You will see the instructions.

mattb2 days ago

This is from the configuration file docs:

"Ii is also possible to use environment variables instead of the configuration file, and these environment variables take precedence over the values in the config file."

Anton Tananaev2 days ago

You have to set CONFIG_USE_ENVIRONMENT_VARIABLES to enable environment variables.

mattb2 days ago

Thanks everyone, I got it working. Much appreciated!

Turbovix2 days ago

Oops, didn’t know it worked that way (need to set CONFIG_USE_ENVIRONMENT_VARIABLES). Live and learn!