|
|
@ -14,7 +14,6 @@ export COMPOSE_DIR='/opt/containers/traccar'
|
|
|
|
export COMPOSE_CTX='ux_vilnius'
|
|
|
|
export COMPOSE_CTX='ux_vilnius'
|
|
|
|
export COMPOSE_PROJECT='traccar-'"${COMPOSE_CTX}"
|
|
|
|
export COMPOSE_PROJECT='traccar-'"${COMPOSE_CTX}"
|
|
|
|
export COMPOSE_FILE="${COMPOSE_DIR}"'/docker-compose.yml'
|
|
|
|
export COMPOSE_FILE="${COMPOSE_DIR}"'/docker-compose.yml'
|
|
|
|
export COMPOSE_OVERRIDE="${COMPOSE_DIR%/}"'/docker-compose.override.yml'
|
|
|
|
|
|
|
|
export COMPOSE_ENV=<add accordingly>
|
|
|
|
export COMPOSE_ENV=<add accordingly>
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
@ -25,20 +24,12 @@ On your deployment machine create the necessary Docker context to connect to and
|
|
|
|
docker context create fully.qualified.domain.name --docker 'host=ssh://root@fully.qualified.domain.name'
|
|
|
|
docker context create fully.qualified.domain.name --docker 'host=ssh://root@fully.qualified.domain.name'
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## Build
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
We build only MySQL. Our local adjustment to the official image is simply adding `/tmp/mysql` to it. See [build-context/mysql/Dockerfile](build-context/mysql/Dockerfile). We use `/tmp/mysql` to bind-mount a dedicated ZFS dataset for MySQL `tmpdir` location.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
docker compose --project-name "${COMPOSE_PROJECT}" --file "${COMPOSE_FILE}" --file "${COMPOSE_OVERRIDE}" --env-file "${COMPOSE_ENV}" --profile 'build-mysql' build
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Pull
|
|
|
|
## Pull
|
|
|
|
|
|
|
|
|
|
|
|
The Traccar image is just pulled from Docker Hub verbatim.
|
|
|
|
Pull both Traccar and MySQL:
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
```
|
|
|
|
docker compose --project-name "${COMPOSE_PROJECT}" --file "${COMPOSE_FILE}" --env-file "${COMPOSE_ENV}" --profile 'traccar' pull
|
|
|
|
docker compose --project-name "${COMPOSE_PROJECT}" --file "${COMPOSE_FILE}" --env-file "${COMPOSE_ENV}" --profile 'full' pull
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## Copy to target
|
|
|
|
## Copy to target
|
|
|
@ -46,16 +37,18 @@ docker compose --project-name "${COMPOSE_PROJECT}" --file "${COMPOSE_FILE}" --en
|
|
|
|
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:
|
|
|
|
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:
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
```
|
|
|
|
source "${COMPOSE_ENV}"
|
|
|
|
images="$(docker compose --project-name "${COMPOSE_PROJECT}" --file "${COMPOSE_FILE}" --env-file "${COMPOSE_ENV}" --profile 'full' config | grep -Pi -- 'image:' | awk '{print $2}' | sort | uniq)"
|
|
|
|
for image in 'mysql:'"${MYSQL_VERSION}" 'traccar/traccar:'"${TRACCAR_VERSION}"; do
|
|
|
|
while IFS= read -u 10 -r image; do
|
|
|
|
copy-docker.sh "${image}" fully.qualified.domain.name
|
|
|
|
copy-docker "${image}" fully.qualified.domain.name
|
|
|
|
done
|
|
|
|
done 10<<<"${images}"
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## Start
|
|
|
|
## Start and clean up
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
```
|
|
|
|
docker --context 'fully.qualified.domain.name' compose --project-name "${COMPOSE_PROJECT}" --file "${COMPOSE_FILE}" --env-file "${COMPOSE_ENV}" --profile 'full' up --detach
|
|
|
|
docker --context 'fully.qualified.domain.name' compose --project-name "${COMPOSE_PROJECT}" --file "${COMPOSE_FILE}" --env-file "${COMPOSE_ENV}" --profile 'full' up --detach
|
|
|
|
|
|
|
|
docker --context 'fully.qualified.domain.name' system prune -af
|
|
|
|
|
|
|
|
docker system prune -af
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
# Initial setup
|
|
|
|
# Initial setup
|
|
|
@ -68,58 +61,63 @@ Create ZFS datasets and set permissions as needed.
|
|
|
|
|
|
|
|
|
|
|
|
* Parent dateset
|
|
|
|
* Parent dateset
|
|
|
|
```
|
|
|
|
```
|
|
|
|
zfs create -o mountpoint=/opt/docker-data 'zpool/docker-data'
|
|
|
|
export "$(grep -Pi -- '^CONTEXT=' "${COMPOSE_ENV}")"
|
|
|
|
|
|
|
|
zfs create -o canmount=off zpool/data/opt
|
|
|
|
|
|
|
|
zfs create -o mountpoint=/opt/docker-data zpool/data/opt/docker-data
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
* Container-specific datasets
|
|
|
|
* Container-specific datasets
|
|
|
|
```
|
|
|
|
```
|
|
|
|
zfs create -p 'zpool/docker-data/traccar-'"${COMPOSE_CTX}"'/traccar/data/data'
|
|
|
|
zfs create -p 'zpool/docker-data/traccar-'"${CONTEXT}"'/traccar/data'
|
|
|
|
zfs create -p 'zpool/docker-data/traccar-'"${COMPOSE_CTX}"'/traccar/data/logs'
|
|
|
|
zfs create -p 'zpool/docker-data/traccar-'"${CONTEXT}"'/traccar/config'
|
|
|
|
zfs create -p 'zpool/docker-data/traccar-'"${COMPOSE_CTX}"'/traccar/config'
|
|
|
|
zfs create -p 'zpool/docker-data/traccar-'"${CONTEXT}"'/mysql/data'
|
|
|
|
zfs create -p 'zpool/docker-data/traccar-'"${COMPOSE_CTX}"'/mysql/data/datadir'
|
|
|
|
zfs create -p 'zpool/docker-data/traccar-'"${CONTEXT}"'/mysql/config'
|
|
|
|
zfs create -p 'zpool/docker-data/traccar-'"${COMPOSE_CTX}"'/mysql/data/tmpdir'
|
|
|
|
|
|
|
|
zfs create -p 'zpool/docker-data/traccar-'"${COMPOSE_CTX}"'/mysql/config'
|
|
|
|
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
* Create subdirs
|
|
|
|
* Create subdirs
|
|
|
|
```
|
|
|
|
```
|
|
|
|
mkdir -p '/opt/docker-data/traccar-'"${COMPOSE_CTX}"'/mysql/config/'{'docker-entrypoint-initdb.d','db'}
|
|
|
|
mkdir -p '/opt/docker-data/traccar-'"${CONTEXT}"'/'{'traccar/data/'{'data','logs'},'mysql/config/'{'docker-entrypoint-initdb.d','db'}}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
This will create a directory structure like so:
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
traccar-loft/
|
|
|
|
|
|
|
|
├── mysql
|
|
|
|
|
|
|
|
│ ├── config
|
|
|
|
|
|
|
|
│ │ ├── db
|
|
|
|
|
|
|
|
│ │ └── docker-entrypoint-initdb.d
|
|
|
|
|
|
|
|
│ └── data
|
|
|
|
|
|
|
|
└── traccar
|
|
|
|
|
|
|
|
├── config
|
|
|
|
|
|
|
|
└── data
|
|
|
|
|
|
|
|
├── data
|
|
|
|
|
|
|
|
└── logs
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
* Change ownership for MySQL daemon
|
|
|
|
* Change ownership for MySQL daemon
|
|
|
|
```
|
|
|
|
```
|
|
|
|
chown -R 999:999 '/opt/docker-data/traccar-'"${COMPOSE_CTX}"'/mysql/'{*,.*}
|
|
|
|
chown -R 999:999 '/opt/docker-data/traccar-'"${CONTEXT}"'/mysql/'*
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## Additional files
|
|
|
|
## Additional files
|
|
|
|
|
|
|
|
|
|
|
|
Place the following files on target server. Use the directory structure at [build-context](build-context) as a guide, specifically at `docker-data`.
|
|
|
|
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`.
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
```
|
|
|
|
build-context/
|
|
|
|
build-context/
|
|
|
|
├── mysql
|
|
|
|
├── mysql
|
|
|
|
│  ├── docker-data
|
|
|
|
│ └── docker-data
|
|
|
|
│  │  ├── config
|
|
|
|
│ └── config
|
|
|
|
│  │  │  ├── db
|
|
|
|
│ └── db
|
|
|
|
│  │  │  │  └── my.cnf
|
|
|
|
│ └── my.cnf
|
|
|
|
│  │  │  └── docker-entrypoint-initdb.d
|
|
|
|
|
|
|
|
│  │  └── data
|
|
|
|
|
|
|
|
│  │  ├── datadir
|
|
|
|
|
|
|
|
│  │  └── tmpdir
|
|
|
|
|
|
|
|
│  ├── ...
|
|
|
|
|
|
|
|
│  └── ...
|
|
|
|
|
|
|
|
└── traccar
|
|
|
|
└── traccar
|
|
|
|
├── docker-data
|
|
|
|
└── docker-data
|
|
|
|
│  ├── config
|
|
|
|
└── config
|
|
|
|
│  │  └── traccar.xml
|
|
|
|
└── traccar.xml
|
|
|
|
│  └── 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. We also add a `tmpdir` whose location gets created in our custom MySQL image up top during [Build](#build). Lastly since we live in a world with MySQL 8.0.30+ we're using `innodb_redo_log_capacity` over Traccar's recommendation (as of Thursday, June 22, 2023) 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).
|
|
|
|
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 8.0 docs section "Running Additional Initialization Scripts"](https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker-additional-init).
|
|
|
|
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.
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
|