tobybatch / kimai2

Docker containers for the kimai2 web application including docker-compose and kubernetes/helm deployment.
MIT License
183 stars 96 forks source link

[BUG] Docker image PHP memory limit #522

Closed chrisonline closed 10 months ago

chrisonline commented 1 year ago

Describe the bug I get "out of memory" error with the default docker settings if I call this command "kimai:reload --env=prod".

To Reproduce

  1. Start the container
  2. Connect to the docker container via SSH terminal
  3. Write php /opt/kimai/bin/console kimai:reload --env=prod
  4. See error

Desktop (please complete the following information):

Additional context To fix this problem, I need to add the "memory_limit" environment variable to the composer file:

  kimai: # This is the latest FPM image of kimai
    image: kimai/kimai2:fpm
    environment:
       ...
      - memory_limit=512M

But I think it would be better to change the docker php.ini default value to 512M instead of the current 128M. So it is working out of the box.

tobybatch commented 10 months ago

@kevinpapst What is the recommended memory limit for running Kimai2?

@chrisonline Without your docker-compose.yml or startup command I can't tell if you're adding extra extensions etc.

And the default docker-compose.yml in the root of the repo does not throw a memory error.

And I checked the FPM prod image as well and that seems to work too.

kevinpapst commented 10 months ago

128M is more than enough for normal setups for the FPM process. The only place where this might fail is the PDF export with large amounts of data.

The error here is about the memory limit of the CLI php process.
Private setups (like this docker image) can use -1 (meaning unlimited) memory.

CLI and FPM should be two different ini files.

tobybatch commented 10 months ago

I can't replicate this. Here is the reload in the prod container. Are you trying to clear the prod env in a dev container?

3f57c90b8e41:/opt/kimai# /opt/kimai/bin/console kimai:reload --env=prod

Reloading configurations ...
============================

 [OK] All 25 YAML files contain valid syntax.

 [OK] All 578 XLIFF files contain valid syntax.

 Rebuilding your cache, please be patient ...

 // Clearing the cache for the prod environment with debug false

 [OK] Cache for the "prod" environment (debug=false) was successfully cleared.

 // Warming up the cache for the prod environment with debug false

 [OK] Cache for the "prod" environment (debug=false) was successfully warmed.

 [OK] Kimai config was reloaded

3f57c90b8e41:/opt/kimai#
chrisonline commented 10 months ago

This is my Stack where I get the problem with the memory. I need to add this line: - memory_limit=512M

version: '3.5'
services:

  sqldb:
    image: mysql:5.7.9
    environment:
      - MYSQL_DATABASE=kimai
      - MYSQL_USER=kimaiuser
      - MYSQL_PASSWORD=xxxxx
      - MYSQL_ROOT_PASSWORD=xxxx
    volumes:
      - /volume2/docker/kimai/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
    container_name: kimai-mysql

  nginx:
    image: tobybatch/nginx-fpm-reverse-proxy
    ports:
      - 40007:80
    volumes:
      - /volume2/docker/kimai/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
    container_name: kimai-proxy

  kimai: # This is the latest FPM image of kimai
    image: kimai/kimai2:fpm
    environment:
      - ADMINMAIL=xxx
      - ADMINPASS=xxxx
      - DATABASE_URL=mysql://kimaiuser:kimaipassword@sqldb/kimai
      - TRUSTED_HOSTS=nginx,localhost,127.0.0.1,192.168.1.50,xxxx
      - memory_limit=512M
    volumes:
      - /volume2/docker/kimai/public:/opt/kimai/public
      - /volume2/docker/kimai/var:/opt/kimai/var
      # - var:/opt/kimai/var
      # - ./ldap.conf:/etc/openldap/ldap.conf:z
      # - ./ROOT-CA.pem:/etc/ssl/certs/ROOT-CA.pem:z
    restart: unless-stopped
    container_name: kimai

  postfix:
    image: catatnight/postfix:latest
    environment:
      maildomain: neontribe.co.uk
      smtp_user: kimai:kimai
    restart: unless-stopped
    container_name: kimai-postfix

volumes:
    var:
    public:
    mysql: