How to Install Kimai on a VPS with Docker: Self-Hosted Time Tracking for Teams and Freelancers

 


There is one question that is always hard to answer at the end of a project: how many hours did this client actually take? An answer based on memory is almost always wrong — small tasks squeezed between meetings go unrecorded, Tuesday's overtime blends into another project, and when the invoice is written, the number feels like a guess. A detail-oriented client will ask for the breakdown, and without tidy time records, there is nothing solid to show them.

Kimai gives that problem structure. This open source time-tracking application records hours per customer, project, and activity, then turns those records into reports and invoices. It suits freelancers billing by the hour as well as small teams that need to see where working hours actually flow. This guide installs Kimai on a VPS with Docker Compose using the official kimai/kimai2 image and MySQL as its database, then secures it behind an Nginx reverse proxy with HTTPS.

Prerequisites

  • A Linux VPS with Docker and Docker Compose v2 installed.
  • A domain pointing at the VPS IP, for example time.example.com. This guide uses that domain; replace it with your own.
  • SSH access to the VPS with sudo rights.
  • Ports 80 and 443 open in the VPS firewall and in the cloud provider firewall, if any.

Check Docker and Compose on the VPS first:

docker --version
docker compose version

Expected output: both commands print a version number without errors.

Step 1: create the folder and the Compose file

Create a working folder at /opt/kimai, then create compose.yml inside it:

sudo mkdir -p /opt/kimai
cd /opt/kimai
sudo nano compose.yml

Fill the file with the configuration below, which follows the official example from Kimai's documentation. Replace every password and sample value with your own:

services:
  sqldb:
    image: mysql:8.3
    volumes:
      - mysql:/var/lib/mysql
    environment:
      - MYSQL_DATABASE=kimai
      - MYSQL_USER=kimaiuser
      - MYSQL_PASSWORD=PUT_A_STRONG_PASSWORD_HERE
      - MYSQL_ROOT_PASSWORD=PUT_A_DIFFERENT_STRONG_ROOT_PASSWORD_HERE
    command: --default-storage-engine innodb
    restart: unless-stopped
    healthcheck:
      test: mysqladmin -uroot -p$$MYSQL_ROOT_PASSWORD ping -h 127.0.0.1 --silent
      interval: 10s
      timeout: 5s
      retries: 12
      start_period: 30s

  kimai:
    image: kimai/kimai2:apache
    depends_on:
      sqldb:
        condition: service_healthy
        restart: true
    volumes:
      - data:/opt/kimai/var/data
      - plugins:/opt/kimai/var/plugins
    ports:
      - 8001:8001
    environment:
      - APP_SECRET=PUT_A_LONG_RANDOM_STRING_HERE
      - "TRUSTED_HOSTS=^time\\.example\\.com$"
      - ADMINMAIL=admin@example.com
      - ADMINPASS=PUT_AN_ADMIN_PASSWORD_HERE
      - "DATABASE_URL=mysql://kimaiuser:PUT_A_STRONG_PASSWORD_HERE@sqldb:3306/kimai"
    restart: unless-stopped

volumes:
  data:
  mysql:
  plugins:

What each part does:

  • sqldb is the MySQL 8.3 database. Its healthcheck makes sure Kimai only starts once the database genuinely accepts connections, not merely once the container is alive.
  • kimai uses the apache image variant, a standalone image with a built-in web server listening on port 8001. This is the simplest choice for a single VPS, since no separate web server is needed.
  • data holds Kimai's application data, plugins holds plugins installed later, and mysql holds the database. All three are Docker volumes, so the data survives container recreation.
  • APP_SECRET is a long random string for session security and internal Symfony encryption; Kimai's documentation stresses that this value must be unique. You can generate one with openssl rand -hex 32 in the VPS terminal.
  • TRUSTED_HOSTS is a regex pattern of the domain used to reach Kimai. Note the escaping: dots in the domain are written as \\. in the YAML file because the value passes through two layers of parsing.
  • ADMINMAIL and ADMINPASS are used on the first start to create the administrator account. DATABASE_URL connects Kimai to the sqldb service — that service name is the database hostname on Docker's internal network.

Save the file (Ctrl+O, Enter, Ctrl+X in nano).

Step 2: start it and check the status

From /opt/kimai, run:

sudo docker compose up -d

The first start takes longer than usual, because Kimai needs to prepare the database and the admin account. Check the status after a minute or two:

sudo docker compose ps
sudo docker compose logs --tail=50 kimai

Expected output: the sqldb and kimai services show as running (or Up), and the kimai log shows the web server listening on port 8001 with no database connection errors. If the log shows repeated connection errors, the most common cause is a password in DATABASE_URL that differs from MYSQL_PASSWORD, or a database still finishing initialization — wait until the sqldb healthcheck passes, then check again.



Step 3: first login and a new admin password

Open http://YOUR_VPS_IP:8001 in a browser. Kimai's login page appears. Sign in with the email from ADMINMAIL and the password from ADMINPASS. Once inside, the first thing worth doing is changing the admin password through the profile menu, especially since the ADMINPASS value sat in the Compose file — that file should not be treated as secret forever.

Next, build the basic recording structure in the three levels Kimai uses: customer, project, and activity. Create one customer (for example a client name), one project under it (for example the job name), and one activity (for example "Development" or "Meeting"). This structure matters because Kimai's reports and invoices filter on all three. Start one timer from the dashboard, let it run, then stop it — your first time entry is now recorded and visible in the timesheet list.

For teams, add other users through the administration menu: each member gets their own account, so working hours never blend into one shared account. If you bill clients by time, set hourly rates as well: rates can sit at customer, project, or activity level, and Kimai calculates the value of time entries automatically.

Step 4: add an Nginx reverse proxy and HTTPS

Port 8001 should not stay open to the public permanently. Point the domain at the container through Nginx, then secure it with Let's Encrypt. Create an Nginx configuration file:

sudo nano /etc/nginx/sites-available/kimai
server {
    listen 80;
    server_name time.example.com;

    client_max_body_size 50M;

    location / {
        proxy_pass http://127.0.0.1:8001;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Enable it, test the configuration, and issue a certificate:

sudo ln -s /etc/nginx/sites-available/kimai /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
sudo certbot --nginx -d time.example.com

Expected output: nginx -t answers syntax is ok and test is successful, and Certbot confirms the certificate was issued. After that, open https://time.example.com — Kimai should load over HTTPS. One value needs to stay in sync: TRUSTED_HOSTS in compose.yml must contain exactly the domain users open. If you change the domain after installation, update that value too, then recreate the container with sudo docker compose up -d.

Step 5: reports, exports, and invoices

Kimai's real value shows when time records become something you can send to a client. From the reporting menu, filter time entries by customer, project, and date range, then export in the format you need — PDF to send directly, CSV or spreadsheet to process further. If hourly rates are filled in, the report shows total hours together with their value, so the invoice figure no longer comes from an estimate.

For billing, Kimai offers an invoice module: pick the unbilled time entries, generate an invoice from them, and download the document. Entries already on an invoice are marked, so nothing gets billed twice. A tidy weekly routine is to review the timesheet at week's end, correct entries with odd durations, and export the report before creating the invoice — fixing things after an invoice is issued is far more awkward than fixing them before.

Step 6: back it up before the time records pile up

Time records are billing evidence. Losing the database means losing the basis for invoices not yet issued. Three volumes belong in the backup plan: mysql (the database), data (application data), and plugins (if you install any). This command dumps the database without stopping the containers:

sudo docker compose exec sqldb mysqldump -u root -p'YOUR_ROOT_PASSWORD' kimai > /opt/kimai/backup-kimai.sql

Replace YOUR_ROOT_PASSWORD with the MYSQL_ROOT_PASSWORD value from compose.yml. Store the dump together with a copy of the data volume somewhere off the VPS, and schedule the command with cron once you are confident the dump restores cleanly.

Troubleshooting

Kimai shows a database connection error on startup.
Check three things in order: (1) sqldb passes its healthcheck (sudo docker compose ps shows it healthy), (2) the password in DATABASE_URL matches MYSQL_PASSWORD exactly — including URL-encoding any special characters such as @, :, /, or %, (3) the service name sqldb was not changed on one side only, since that name is the database hostname.

The admin login fails even though the containers run.
Make sure you are using the current ADMINMAIL and ADMINPASS values from compose.yml. If you changed ADMINPASS after the first start, the already-created admin account does not change with it — change the password from inside the application after logging in, or create a new admin user from the administration menu.

Blank page or untrusted-host error after adding the reverse proxy.
This is almost always about TRUSTED_HOSTS: the regex must match exactly the domain being opened, with dots escaped (\\.) inside the YAML file. Also check proxy_set_header Host $host; in the Nginx configuration — without the correct Host header, Kimai receives the wrong hostname.

Port 8001 is already used by another application.
Change the port mapping in compose.yml to a free port, for example 8002:8001, adjust proxy_pass in Nginx, then run sudo docker compose up -d. The right-hand side (container) port stays 8001, since that is the port the apache image listens on.

Updating to a newer version.
Kimai's official documentation describes the flow briefly: pull the latest image, stop the old stack, start again. The commands:

sudo docker compose pull
sudo docker compose down
sudo docker compose up -d

The data, mysql, and plugins volumes are not removed by down without the -v flag, so the data survives. Do not add -v unless you genuinely mean to delete all data.

Summary table

ComponentRolePort / location
kimai (kimai/kimai2:apache)The time-tracking application8001 on host and container
sqldb (MySQL 8.3)The time-record databaseVolume mysql
Volume dataKimai application data/opt/kimai/var/data in the container
Volume pluginsExtra plugins/opt/kimai/var/plugins in the container
Nginx + CertbotHTTPS for the public domainPorts 80 and 443

Pre-finish checklist

  • The sqldb and kimai containers are running, and sqldb passes its healthcheck.
  • The first admin login works, and the admin password has been changed from the value in compose.yml.
  • One customer, one project, and one activity exist, and one time entry has been recorded through the timer.
  • TRUSTED_HOSTS matches the domain in use, and the domain loads over https:// with a valid certificate.
  • A report exports for one date range, and hourly rates (if used) calculate values correctly.
  • The database dump and the data volume are covered by a recurring backup plan.

One maintenance note: update the image periodically with the update commands above from /opt/kimai, then check the log afterwards. Plugins installed through the plugins volume need a compatibility check every time the Kimai version rises.

Have you ever billed a project with an hours figure that was really just an estimate? What most often wrecks your time records — forgetting to start the timer, or entries mixed across projects? Tell us in the comments, and if any step above fails on your VPS, paste the error message so it can be discussed together.

Read also: the Rnevio article “Docker Compose for Self-Hosting from Scratch” explains the Compose pattern used in this guide from the ground up, while the companion guide in this batch is available in the Snipe-IT guide for IT asset management on a VPS.

Diskusi

Ada pertanyaan atau pengalaman yang ingin dibagikan?

0komentar

Komentar ditinjau sebelum ditampilkan. Mari berdiskusi dengan sopan dan sesuai topik.