A
A
Alexander Urich2021-12-15 14:16:59
symfony
Alexander Urich, 2021-12-15 14:16:59

How to correctly pass the environment in Symfony and Docker?

Good afternoon. There is a project on Symfony. You need to run it in docker
1. The docker image is built via docker build -f ./.docker/Dockerfile -t container_name .
2. Run in docker with environment variables specified docker run --rm --env-file=/path/to/.env container_name

container is started. But the environment from the /path/to/.env file is somehow not transferred in the right way...
I go into the bash container, enter ./bin/console debug:dotenv and get the error:
[ERROR] Dotenv component is not initialized.

I type ./bin/console debug:container --env-vars

Output:
No environment variables are being used.

Dockerfile

FROM php:8.1.0-fpm-buster

RUN apt-get update && apt-get install -y \
        zip \
        libzip-dev \
        libpq-dev \
        librabbitmq-dev \
    && rm -r /var/lib/apt/lists/* \
    && docker-php-ext-install pdo_pgsql

RUN pecl install amqp-1.11.0

RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

COPY . /var/www/action-log

COPY ./.docker/php/conf/php/php.prod.ini "$PHP_INI_DIR/conf.d/actionlog.php.ini"

COPY ./.docker/php/conf/php/www-fpm-pool.prod.conf "$PHP_INI_DIR/php-fpm-pool.conf"

WORKDIR /var/www/action-log

RUN /usr/local/bin/composer install --optimize-autoloader --ignore-platform-req=php

RUN /usr/local/bin/composer dump-env prod

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question