Skip to content

Slow container startup (1m 32s) when using custom PUID/PGID #557

@tomaskir

Description

@tomaskir

Support guidelines

I've found a bug and checked that ...

  • ... the documentation does not mention anything about my problem
  • ... there are no open or closed issues that are related to my problem

Description

Greetings,

When using my own PUID/PGID, the Libre containers (server, dispatcher, syslog, snmptrap) take 1 minute 30 seconds to start each.

services:
  nms.x.internal:
    image: librenms/librenms:26.2.0
...
    environment:
      - PUID=${PUID}
      - PGID=${PGID}
...

The root cause of the issue is here:

find /data/logs ${LIBRENMS_PATH}/composer* ${LIBRENMS_PATH}/config.d ${LIBRENMS_PATH}/bootstrap ${LIBRENMS_PATH}/logs ${LIBRENMS_PATH}/storage ${LIBRENMS_PATH}/vendor \( ! -user librenms -o ! -group librenms \) -exec chown librenms:librenms {} +

The issue is in the /opt/librenms/vendor, which has many files:

3ae6986beb62:/etc/cont-init.d# find /opt/librenms/vendor | wc -l
11683
3ae6986beb62:/etc/cont-init.d# 

This command takes excessively long to run:

docker compose run -it --rm --entrypoint bash nms.x.internal-syslog
...
7f53b6cc3442:/opt/librenms# 
7f53b6cc3442:/opt/librenms# cd /etc/cont-init.d/
7f53b6cc3442:/etc/cont-init.d# bash 00-fix-logs.sh 
7f53b6cc3442:/etc/cont-init.d# bash 01-fix-uidgid.sh 
Switching to PGID 805...
Switching to PUID 805...
7f53b6cc3442:/etc/cont-init.d# bash 02-fix-perms.sh 
Fixing perms...
7f53b6cc3442:/etc/cont-init.d# time find /opt/librenms/vendor \( ! -user librenms -o ! -group librenms \) -exec chown librenms:librenms {} +

real    1m32.008s
user    0m0.069s
sys     0m3.614s
7f53b6cc3442:/etc/cont-init.d# 

This could be replaced with a simple:

chown -R --from=root:root librenms:librenms ${LIBRENMS_PATH}/vendor

And removing the ${LIBRENMS_PATH}/vendor from the existing find ... -exec call.

This would have the same effect, but take only seconds. Here is a fresh container run with the updated command:

docker compose run -it --rm --entrypoint bash nms.x.internal-syslog
...
3ae6986beb62:/opt/librenms# cd /etc/cont-init.d/
3ae6986beb62:/etc/cont-init.d# bash 00-fix-logs.sh 
3ae6986beb62:/etc/cont-init.d# bash 01-fix-uidgid.sh 
Switching to PGID 805...
Switching to PUID 805...
3ae6986beb62:/etc/cont-init.d# bash 02-fix-perms.sh 
Fixing perms...
3ae6986beb62:/etc/cont-init.d# time chown -R --from=root:root librenms:librenms /opt/librenms/vendor

real    0m0.282s
user    0m0.024s
sys     0m0.257s
3ae6986beb62:/etc/cont-init.d# 

This would take down container startup time from 1 minute 30+ seconds to almost instant.

Expected behaviour

Container will start fast.

Actual behaviour

Container takes 1 minute 30+ seconds to start.

Steps to reproduce

Run container with custom PUID/PGID:

services:
  nms.x.internal:
    image: librenms/librenms:26.2.0
...
    environment:
      - PUID=${PUID}
      - PGID=${PGID}
...

Docker info

Client: Docker Engine - Community
 Version:    29.2.1
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.31.1
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v5.0.2
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Docker Compose config

Logs

not applicable

Additional info

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions