0

We are running a laravel application by docker. We are creating a docker container using PHP-FPM (php:7.0-fpm official image) & NGINX. We use a common .env file for both docker and laravel applications.

we up & running our application by - docker-compose --env-file=./.env -f docker-compose.yml up -d

But the problem is when we change our .env file, the application not detected the change. We want to get every .env file change without re-creating the container.

Dockerfile -

FROM php:7.0-fpm

# PHP_CPPFLAGS are used by the docker-php-ext-* scripts
ENV PHP_CPPFLAGS="$PHP_CPPFLAGS -std=c++11"

# Install dependencies
RUN apt-get update && apt-get install -y \
    nginx \
    libpng-dev \
    zlib1g-dev \
    libsasl2-dev \
    libssl-dev \
    libjpeg62-turbo-dev \
    libfreetype6-dev \
    libpng-dev \
    libxpm-dev \
    libvpx-dev \
    libxml2-dev \
    libicu-dev \
    git

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install extensions
RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
RUN docker-php-ext-configure intl
RUN docker-php-ext-install -j$(nproc) pdo_mysql mbstring zip calendar soap gd intl

# Install mongodb extension
RUN pecl install mongodb-1.4.4 \
    && echo "extension=mongodb.so" > /usr/local/etc/php/conf.d/mongo.ini

# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --version=1.8.6
RUN composer global require hirak/prestissimo

COPY entrypoint.sh /etc/entrypoint.sh
RUN chmod +x /etc/entrypoint.sh

RUN usermod -u 1000 www-data

# Set working directory
WORKDIR /var/www

EXPOSE 80 443

Docker Compose -

version: '3.5'
services:
  api-service:
    environment:
      SERVICE_NAME: app
      VIRTUAL_HOST: ${API_DOMAIN}
    working_dir: /var/www
    entrypoint: /etc/entrypoint.sh
    volumes:
      - ../../:/var/www
      - ../nginx/conf.d/nginx-local.conf:/etc/nginx/sites-enabled/default
      - ../php/local.ini:/usr/local/etc/php/conf.d/local.ini
      - ../php/memory_limit.ini:/usr/local/etc/php/conf.d/memory_limit.ini
      - ../php/php.ini:/usr/local/etc/php/conf.d/php.override.ini
      - ../php/www.conf:/usr/local/etc/php-fpm.d/www.conf
    ports:
      - ${PORT}:80

networks:
  api-service-network:
    external:
      name: ${EXTERNAL_NETWORK}

entrypoint -

#!/usr/bin/env bash
service nginx start
php-fpm

So is it possible to reload ENV (on local development by PHP-FPM) without recreating the container.

1 Answer 1

0

Try using env_file in docker-compose

Maybe can help you

Sign up to request clarification or add additional context in comments.

2 Comments

I think it is doing the same thing - docker-compose --env-file=./.env -f docker-compose.yml up -d
Maybe its better pass the .env via volumes (for laravel) cause volumes has bind

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.