Docker Compose files to spin up an instance of Traccar.
# How to run
Add a `COMPOSE_ENV` file and save its location as a shell variable along with the location where this repo lives, here for example `/opt/containers/traccar` plus all other variables. At [env/fqdn_context.env.example](env/fqdn_context.env.example) you'll find an example environment file.
When everything's ready start Traccar with Docker Compose, otherwise head down to [Initial setup](#initial-setup) first.
On your deployment machine create the necessary Docker context to connect to and control the Docker daemon on whatever target host you'll be using, for example:
Copy images to target Docker host, that is assuming you deploy to a machine that itself has no network route to reach Docker Hub. Copying in its simplest form involves a local `docker save` and a remote `docker load`. Consider the helper mini-project [quico.space/Quico/copy-docker](https://quico.space/Quico/copy-docker) where [copy-docker.sh](https://quico.space/Quico/copy-docker/src/branch/main/copy-docker.sh) allows the following workflow:
We're assuming you run Docker Compose workloads with ZFS-based bind mounts. ZFS management, creating a zpool and setting adequate properties for its datasets is out of scope of this document.
## Datasets
Create ZFS datasets and set permissions as needed.
Place both a `my.cnf` and `traccar.xml` file on target server. Use the directory structure at [build-context](build-context) as a guide, specifically at `docker-data`.
The [example my.cnf](build-context/mysql/docker-data/config/db/my.cnf) config file for MySQL follows [Traccar's recommendation for MySQL](https://www.traccar.org/mysql-optimization/) but uses 512 MiB of RAM instead of Traccar's 3 GiB example. Since we live in a world with MySQL 8.0.30+ we're using `innodb_redo_log_capacity` over Traccar's recommendation (as of Wednesday, March 5, 2025) of `innodb_log_file_size`. See also [MySQL 8.0 docs section "Configuring Redo Log Capacity (MySQL 8.0.30 or Higher)"](https://dev.mysql.com/doc/refman/8.0/en/innodb-redo-log.html#innodb-modifying-redo-log-capacity).
In `docker-entrypoint-initdb.d` you can store database initialization scripts that are run when you start MySQL without any data. See also [MySQL 9.2 docs section "Running Additional Initialization Scripts"](https://dev.mysql.com/doc/refman/9.2/en/docker-mysql-more-topics.html#docker-additional-init).
Config `traccar.xml` is a minimal working example file taken from the Traccar Docker image. See [Docker Hub traccar/traccar overview](https://hub.docker.com/r/traccar/traccar) section "Get default traccar.xml". In [our example traccar.xml](build-context/traccar/docker-data/config/traccar.xml) file the default H2 database is replaced with MySQL to match this repo.
When done head back up to [How to run](#how-to-run).