traccar / traccar-docker

Traccar Docker
298 stars 145 forks source link

Traccar in Docker

Traccar GPS Tracking System in Docker image.

Official website: https://www.traccar.org
DockerHub image: https://hub.docker.com/r/traccar/traccar
Maintainer: Maxim Zalysin

Available tags:

6.X

Available multi-platform images:

Alpine based: linux/amd64, linux/arm64
Debian based: linux/amd64, linux/arm64
Ubuntu based: linux/amd64, linux/arm64, linux/arm/v7

Container create example:

  1. Create work directories:

    mkdir -p /opt/traccar/logs
  2. Get default traccar.xml:

    docker run \
    --rm \
    --entrypoint cat \
    traccar/traccar:latest \
    /opt/traccar/conf/traccar.xml > /opt/traccar/traccar.xml
  3. Edit traccar.xml: https://www.traccar.org/configuration-file/

  4. Create container:

    docker run \
    --name traccar \
    --hostname traccar \
    --detach --restart unless-stopped \
    --publish 80:8082 \
    --publish 5000-5150:5000-5150 \
    --publish 5000-5150:5000-5150/udp \
    --volume /opt/traccar/logs:/opt/traccar/logs:rw \
    --volume /opt/traccar/traccar.xml:/opt/traccar/conf/traccar.xml:ro \
    traccar/traccar:latest

Database

The default when executing the above docker run command is an internal H2 database but this should only be for basic use.
The docker run command also doesn't create a mount point on the host for the data folder which will cause the database to be lost when the container is recreated. This point can be mitigated by adding the line -v /var/docker/traccar/data:/opt/traccar/data:rw \ after -v /var/docker/traccar/traccar.xml:/opt/traccar/conf/traccar.xml:ro \ but it will still be using the H2 database.
The recommended solution for production use is to link to an external MySQL database and update the configuration .xml-file according to the Traccar MySQL documentation and using the docker run command as-is.

Default JVM options: