Skip to content

Commit

Permalink
docker compose examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpapst committed Nov 17, 2023
1 parent 2d7bf4d commit f8c8c68
Show file tree
Hide file tree
Showing 3 changed files with 292 additions and 58 deletions.
2 changes: 1 addition & 1 deletion _data/menu-documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ on-premise:
icon: bx bxl-docker
name: Docker
description: Running and updating containerized Kimai images
pages: [ docker, kubernetes, docker-updates, building-docker, docker-troubleshooting ]
pages: [ docker, docker-compose, kubernetes, docker-updates, building-docker, docker-troubleshooting ]
- id: on-premise
icon: bx bx-server
name: DevOps
Expand Down
291 changes: 291 additions & 0 deletions _documentation/docker/docker-compose.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,291 @@
---
title: Docker Compose
description: Running Kimai with Docker compose
canonical: /documentation/docker-compose.html
---

This will run the latest prod version using FPM with an nginx reverse proxy:

```dockerfile
version: '3.5'
services:

sqldb:
image: mysql:5.7
environment:
- MYSQL_DATABASE=kimai
- MYSQL_USER=kimaiuser
- MYSQL_PASSWORD=kimaipassword
- MYSQL_ROOT_PASSWORD=changemeplease
volumes:
- mysql:/var/lib/mysql
command: --default-storage-engine innodb
restart: unless-stopped
healthcheck:
test: mysqladmin -p$$MYSQL_ROOT_PASSWORD ping -h localhost
interval: 20s
start_period: 10s
timeout: 10s
retries: 3

nginx:
image: tobybatch/nginx-fpm-reverse-proxy
ports:
- 8001:80
volumes:
- public:/opt/kimai/public:ro
restart: unless-stopped
depends_on:
- kimai
healthcheck:
test: wget --spider http://nginx/health || exit 1
interval: 20s
start_period: 10s
timeout: 10s
retries: 3

kimai:
image: kimai/kimai2:latest
environment:
- [email protected]
- ADMINPASS=changemeplease
- DATABASE_URL=mysql://kimaiuser:kimaipassword@sqldb/kimai?charset=utf8&serverVersion=5.7
- TRUSTED_HOSTS=nginx,localhost,127.0.0.1
- MAILER_URL=smtp://mailer:1025
- [email protected]
volumes:
- public:/opt/kimai/public
# - var:/opt/kimai/var
# - ./ldap.conf:/etc/openldap/ldap.conf:z
# - ./ROOT-CA.pem:/etc/ssl/certs/ROOT-CA.pem:z
restart: unless-stopped

phpmyadmin:
image: phpmyadmin
restart: always
ports:
- 8081:80
environment:
- PMA_ARBITRARY=1

swagger:
image: swaggerapi/swagger-ui
ports:
- 8080:8080
volumes:
- ./swagger.json:/swagger.json
environment:
- SWAGGER_JSON=/swagger.json

mailer:
image: schickling/mailcatcher
ports:
- "${MAILER_SMTP_PORT:-1025}:1025"
- "${MAILER_ADMIN_PORT:-1080}:1080"

volumes:
var:
public:
mysql:
```

## More examples

Listed here are example setups for running the image(s).
If you'd like to contribute a new one them please [raise a PR for this page](https://github.com/kimai/www.kimai.org/edit/main/_documentation/docker/docker-compose.md).

Be aware that none of these images persist the DB between restarts, unless you add a volume to do that:
```dockerfile
volumes:
- mysql:/var/lib/mysql
```

### Apache dev

```dockerfile
version: '3.5'
services:

sqldb:
image: mysql:5.7
environment:
- MYSQL_DATABASE=kimai
- MYSQL_USER=kimaiuser
- MYSQL_PASSWORD=kimaipassword
- MYSQL_ROOT_PASSWORD=changemeplease
command: --default-storage-engine innodb
restart: unless-stopped
healthcheck:
test: mysqladmin -p$$MYSQL_ROOT_PASSWORD ping -h localhost
interval: 20s
start_period: 10s
timeout: 10s
retries: 3

kimai:
image: kimai/kimai2:apache-dev
ports:
- 8001:8001
environment:
- [email protected]
- ADMINPASS=changemeplease
- "DATABASE_URL=mysql://kimaiuser:kimaipassword@sqldb/kimai?charset=utf8&serverVersion=5.7"
- TRUSTED_HOSTS=nginx,localhost,127.0.0.1
restart: unless-stopped
```

### Apache prod

```dockerfile
version: '3.5'
services:

sqldb:
image: mysql:5.7
volumes:
- kimai-mysql:/var/lib/mysql
environment:
- MYSQL_DATABASE=kimai
- MYSQL_USER=kimaiuser
- MYSQL_PASSWORD=kimaipassword
- MYSQL_ROOT_PASSWORD=changemeplease
command: --default-storage-engine innodb
restart: unless-stopped
healthcheck:
test: mysqladmin -p$$MYSQL_ROOT_PASSWORD ping -h localhost
interval: 20s
start_period: 10s
timeout: 10s
retries: 3

kimai:
image: kimai/kimai2:apache
volumes:
- kimai-var:/opt/kimai/var
ports:
- 8001:8001
environment:
- [email protected]
- ADMINPASS=changemeplease
- "DATABASE_URL=mysql://kimaiuser:kimaipassword@sqldb/kimai?charset=utf8&serverVersion=5.7"
- TRUSTED_HOSTS=nginx,localhost,127.0.0.1
restart: unless-stopped

volumes:
kimai-var:
kimai-mysql:
```

### FPM dev

```dockerfile
version: '3.5'
services:

sqldb:
image: mysql:5.7
environment:
- MYSQL_DATABASE=kimai
- MYSQL_USER=kimaiuser
- MYSQL_PASSWORD=kimaipassword
- MYSQL_ROOT_PASSWORD=changemeplease
command: --default-storage-engine innodb
restart: unless-stopped
healthcheck:
test: mysqladmin -p$$MYSQL_ROOT_PASSWORD ping -h localhost
interval: 20s
start_period: 10s
timeout: 10s
retries: 3

nginx:
image: tobybatch/nginx-fpm-reverse-proxy
ports:
- 8001:80
volumes:
- public:/opt/kimai/public:ro
restart: unless-stopped
depends_on:
- kimai
healthcheck:
test: wget --spider http://nginx/health || exit 1
interval: 20s
start_period: 10s
timeout: 10s
retries: 3

kimai:
image: kimai/kimai2:fpm-dev
environment:
- [email protected]
- ADMINPASS=changemeplease
- "DATABASE_URL=mysql://kimaiuser:kimaipassword@sqldb/kimai?charset=utf8&serverVersion=5.7"
- TRUSTED_HOSTS=nginx,localhost,127.0.0.1
volumes:
- public:/opt/kimai/public
# - var:/opt/kimai/var
# - ./ldap.conf:/etc/openldap/ldap.conf:z
# - ./ROOT-CA.pem:/etc/ssl/certs/ROOT-CA.pem:z
restart: unless-stopped

volumes:
var:
public:
```

### FPM prod

```dockerfile
version: '3.5'
services:

sqldb:
image: mysql:5.7
environment:
- MYSQL_DATABASE=kimai
- MYSQL_USER=kimaiuser
- MYSQL_PASSWORD=kimaipassword
- MYSQL_ROOT_PASSWORD=changemeplease
command: --default-storage-engine innodb
restart: unless-stopped
healthcheck:
test: mysqladmin -p$$MYSQL_ROOT_PASSWORD ping -h localhost
interval: 20s
start_period: 10s
timeout: 10s
retries: 3

nginx:
image: tobybatch/nginx-fpm-reverse-proxy
ports:
- 8001:80
volumes:
- public:/opt/kimai/public:ro
restart: unless-stopped
depends_on:
- kimai
healthcheck:
test: wget --spider http://nginx/health || exit 1
interval: 20s
start_period: 10s
timeout: 10s
retries: 3

kimai:
image: kimai/kimai2:latest
environment:
- [email protected]
- ADMINPASS=changemeplease
- "DATABASE_URL=mysql://kimaiuser:kimaipassword@sqldb/kimai?charset=utf8&serverVersion=5.7"
- TRUSTED_HOSTS=nginx,localhost,127.0.0.1
volumes:
- public:/opt/kimai/public
# - var:/opt/kimai/var
# - ./ldap.conf:/etc/openldap/ldap.conf:z
# - ./ROOT-CA.pem:/etc/ssl/certs/ROOT-CA.pem:z
restart: unless-stopped

volumes:
var:
public:
```
57 changes: 0 additions & 57 deletions _documentation/docker/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,6 @@ Keep in mind that this Docker setup is transient and the data will disappear whe
docker rm kimai-mysql-testing kimai-test
```

## Using docker-compose

This will run the latest prod version using FPM with an nginx reverse proxy

See the [[docker-compose.yml]({{ site.kimai_v2_docker }}/blob/main/docker-compose.yml)] in the root of this repo.

### Examples

Listed here are example setups for running the image(s). If you'd like to contribute a new one them please raise a PR for this page.
* [Apache dev]({{ site.kimai_v2_docker }}/tree/main/compose/docker-compose.apache.dev.yml)
* [Apache prod]({{ site.kimai_v2_docker }}/tree/main/compose/docker-compose.apache.prod.yml)
* [FPM dev]({{ site.kimai_v2_docker }}/tree/main/compose/docker-compose.fpm.dev.yml)
* [FPM prod]({{ site.kimai_v2_docker }}/tree/main/compose/docker-compose.fpm.prod.yml)
None of these images persist the DB between restarts, you will need to add a volume to do that:
```dockerfile
volumes:
- mysql:/var/lib/mysql
```
See the [docker-compose.yml](../docker-compose.yml) in the root of the repo.
## Runtime Arguments

The following settings can set at runtime:
Expand Down Expand Up @@ -138,20 +115,6 @@ The ```DB_TYPE``` must be `mysql`:



{% comment %}

### Build the docker
Expand Down Expand Up @@ -181,26 +144,6 @@ Considering you started the machine named `default`, you find the IP with:
docker-machine ip default
```
### Running commands in the docker

You can run any command in the container in this fashion once it is started. Add `-ti` to attach a terminal.

```bash
docker exec -ti kimai2 bash
```

#### Create a user and dummy data

This creates a user admin/password with all privileges.
```bash
docker exec kimai2 /opt/kimai/bin/console kimai:user:create admin [email protected] ROLE_SUPER_ADMIN password
```

To install the test data (fixtures):
```bash
docker exec kimai2 /opt/kimai/bin/console kimai:reset:dev
```

### Using a custom local.yaml
You can mount a [custom configuration]({% link _documentation/local-yaml.md %}) into the container while starting it:
Expand Down

0 comments on commit f8c8c68

Please sign in to comment.