getenv('MY_VAR') in PHP in docker images not working

#1
I use the image litespeedtech/openlitespeed:1.8.1-lsphp82 and in the process of building the image I add various environment variables via services.env file (see the docker stuff below).

In PHP I'd need those values via getenv(). For example to retrieve an API-key. But these calls always return nothing.

I saw that the values can be added via OLS webadmin in the external app in the "environment" textfield and then it works. But that is not a viable solution for me, since I want to be able to create and delete the containers without much configuration.

Did I miss something in the configuration of PHP or is this just not possible? Do I have to write a custom logic, which adds env entries to the httpd_conf.conf? (because that would work, but is rather ugly in my eyes)

Dockerfile "Dockerfile.backend"
Code:
FROM litespeedtech/openlitespeed:1.8.1-lsphp82 AS processwire

RUN apt-get update && apt-get install -y unzip locales locales-all && locale-gen en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV LC_ALL=en_US.UTF-8
ENV PHP_MEMORY_LIMIT=512M
ENV PHP_MAX_EXECUTION_TIME=180

# Modify php.ini to include E in variables_order
RUN sed -i 's/variables_order = "GPCS"/variables_order = "EGPCS"/' /usr/local/lsws/lsphp82/etc/php/8.2/litespeed/php.ini


EXPOSE 80 443 7080
The docker compose part
YAML:
  backend:
    deploy:
      resources:
        limits:
          memory: 4G
    container_name: backend
    build:
      context: ..
      dockerfile: ./.docker/Dockerfile.backend
      target: processwire
    ports:
      - "81:80"
      - "4443:443"
      - "7070:7080"
    volumes:
      - type: bind
        source: ../backend
        target: /var/www/vhosts/localhost/html
    networks:
      - services
    environment:
      <<: *common-env
      XDEBUG_MODE: develop,debug
    env_file:
      - services.env
Thanks in advance.
 
Top