Skip to content

Instantly share code, notes, and snippets.

@chk1
Last active April 20, 2022 00:41
Show Gist options
  • Save chk1/8f7212d7c1538b82af31f7974f6462dc to your computer and use it in GitHub Desktop.
Save chk1/8f7212d7c1538b82af31f7974f6462dc to your computer and use it in GitHub Desktop.
Building/installing Traccar with a Maven Docker container

Installing Traccar via Docker

... without installing Maven on your computer. This process will use the Docker container maven:3.5-jdk-8-alpine instead of a local Maven installation.

I used Ubuntu 16.04 server with the NGINX webserver.

📢 Deprecation notice 2019-06-29 📢

Traccar can now be run in Docker without building it yourself, just get the container from Docker Hub: https://hub.docker.com/r/traccar/traccar/

The information below may still be useful for old installations or as a guideline for building similar Docker containers.

The nginx config and tk905 commands are still valid.

Steps

  1. Install Docker and git
  2. Grab a Traccar release, I used the v3.15 source code zip
  3. Extract it: unzip v3.15.zip
  4. Git clone the Traccar web frontend repository into the "traccar-web" folder, matching the v3.15 version:
    git clone --depth 1 --branch v3.15 https://github.com/tananaev/traccar-web.git traccar-3.15/traccar-web
  5. Copy the modified build.sh (see below in this gist) into setup/docker and run it from the Traccar-3.15 main folder:
    ./setup/docker/build.sh
  6. After the build has succeeded, start the container (see options in the Traccar Documentation):
    docker run -d --name traccar-server -p 5000-5150:5000-5150 -p 8082:8082 tananaev/traccar:3.15-SNAPSHOT
  7. The Traccar web interface will now be available at http://localhost:8082 (after 10-20 or so seconds), login with the default admin/admin, change your password, disable registration... etc. Your Traccar installation is complete and running.
  8. Configure your web server (see NGINX config file in this gist, for example) and open ports in your firewall, if you know the required ones for your device:
    ufw allow 5055 # phone app
    ufw allow 5093 # tk905

Resources and Repositories

#!/bin/bash
# This is a modified version of the Traccar Docker build script:
# https://github.com/tananaev/traccar/blob/master/setup/docker/build.sh
# Commented out: No need to check for Maven on local computer:
# which mvn &> /dev/null || { echo >&2 "Maven package cant be found on path. Aborting."; exit 1; }
which awk &> /dev/null || { echo >&2 "Awk package cant be found on path. Aborting."; exit 1; }
which docker &> /dev/null || { echo >&2 "Docker package cant be found on path. Aborting."; exit 1; }
# Commented out: Don't try to run Maven on local computer
# mvn package || { echo >&2 "Maven package has failed. Aborting."; exit 1; }
# From the Maven Docker repository readme:
# "You can run a Maven project by using the Maven Docker image directly, passing a Maven command to docker run"
sudo docker run -it --rm --name my-maven-project -v "$PWD":/usr/src/mymaven -w /usr/src/mymaven maven:3.5-jdk-8-alpine mvn package
export company=${1:-"tananaev"}
export software=${2:-"traccar"}
export _version=$(head -n 10 ./pom.xml |grep version|cut -d ">" -f2|cut -d"<" -f1)
export version=${3:-$_version}
tmp="./setup/docker/tmp"
mkdir -p ${tmp}
cat ./setup/traccar.xml | awk '/config.default/ && !modif { print;printf(" <entry key=\"web.debug\">true</entry>\n");next; modif=1 } {print}' > ${tmp}/traccar.xml
cp -rf ./setup/default.xml ${tmp}
cp -rf ./schema ${tmp}/schema
cp -rf ./templates ${tmp}/templates
cp -rf ./target/tracker-server.jar ${tmp}/traccar-server.jar
cp -rf ./target/lib ${tmp}/lib
if [ -d ./traccar-web/web ]; then
cp -rf ./traccar-web/web ${tmp}/web
else
mkdir ${tmp}/web
fi
sudo docker build -t ${company}/${software}:${version} ./setup/docker/
rm -rf ${tmp}
server {
listen 80;
listen [::]:80;
server_name EXAMPLE.COM;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name EXAMPLE.COM;
ssl on;
ssl_certificate EXAMPLE.COM_fullchain.crt;
ssl_certificate_key EXAMPLE.COM.key;
ssl_trusted_certificate EXAMPLE.COM/chain.crt;
# Redirect default port (80/443) to Traccar web (8082)
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://127.0.0.1:8082;
}
# Settings needed for WebSockets with NGINX
# https://www.nginx.com/blog/websocket-nginx/
location /api/socket {
proxy_pass http://127.0.0.1:8082;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
# Redirect Let's Encrypt folder to other local directory
location ^~ /.well-known/acme-challenge/ {
default_type "text/plain";
root /srv/www/html;
}
}
# TK905 configuration for GPRS and custom backend
# Send the following texts as SMS to your TK905 device with the SIM card inserted
# Reset device
begin123456
# Set up internet (O2 Germany), username and password not required or can be random
apn123456 pinternet.interkom.de
apnuser123456 a
apnpasswd123456 b
gprs123456
# Change backend to own server, port 5093
adminip123456 123.123.123.123 5093
# Change gps update refresh rate to 30sec
upload123456 30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment