简体   繁体   中英

Laravel specify different name from `.env` or make ingore `.env` in order not to conflict with docker and docker-compose

Because I use docker and docker-compose instead of Homestead and any Vargrant -based solution for development, I want to avoid conflict with laravel on the use of .env file. Therefore, I want for the laravel not to look for this file, instead fetch the required settings data from environmental variables.

So how I can specify, configure the laravel NOT to look for .env file? If that is not possible how I can change the name of the file to search for environmental variables and settings?

The docker-compose.yml is located on the project's root folder.

My docker-compose.yml is the:

version: '3.1'
services:
  develop:
    image: ddesyllas/php-dev:${TAG}
    volumes:
      - ".:/var/www/html"
    links: 
      - memcache
    environment:
      DB_CONNECTION: postgresql
      DB_HOST : postgresql
      DB_PORT : 5432
      DB_DATABASE: ${DOCKER_POSTGRES_DB}
      DB_USERNAME: ${DOCKER_POSTGRES_USER}
      DB_PASSWORD: ${DOCKER_POSTGRES_PASSWORD}

  nginx:
    image: nginx:alpine
    ports:
      - 7880:7880
    links:
      - "develop:develop"
    volumes:
      - ".:/var/www/html"
      - "./docker/nginx.conf:/etc/nginx/nginx.conf:ro"


  postgresql:
    image: postgres:alpine
    volumes:
      - './docker/misc_volumes/postgresql:/var/lib/postgresql/data'
    environment:
      POSTGRES_USER: ${DOCKER_POSTGRES_USER}
      POSTGRES_DB: ${DOCKER_POSTGRES_DB}
      POSTGRES_PASSWORD: ${DOCKER_POSTGRES_PASSWORD}

  memcache:
    image: memcached:alpine

Therefore there's the need for global settings in an aoproach use once-apply globally approach. For example I do not want my laravel application to have access into the ${TAG} enviromental variable at all.

In your docker-compose.yml you can specify the env_file different then .env like:

version: "3.1"
services:
  webserver:
    image: nginx:alpine
    restart: always
    container_name: laravel-webserver
    working_dir: /application
    env_file:
      - .env_docker
    networks: 
      - intranet

networks:
  intranet:
    external: false

Here the docker-compose.yml will use .env_docker instead of .env

Edited:

If you would like to use the different file for the laravel .env then you can change the volumns section to specify that Like:

volumes:
      - ".:/var/www/html"
      - "./docker/nginx.conf:/etc/nginx/nginx.conf:ro"
      - "/<path to your different env file>:/var/www/html/.env"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM