Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker4laravel .env file is overritten by laravel .env file when you docker compose up -d #2

Open
ainsofs opened this issue Apr 1, 2023 · 3 comments

Comments

@ainsofs
Copy link

ainsofs commented Apr 1, 2023

Codebase

Host OS

wsl - debian

Docker info output

 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.10.0)
  compose: Docker Compose (Docker Inc., v2.15.1)
  dev: Docker Dev Environments (Docker Inc., v0.0.5)
  extension: Manages Docker extensions (Docker Inc., v0.2.17)
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0)
  scan: Docker Scan (Docker Inc., v0.23.0)

Server:
 Containers: 26
  Running: 5
  Paused: 0
  Stopped: 21
 Images: 16
 Server Version: 20.10.22
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 9ba4b250366a5ddde94bb7c9d1def331423aa323
 runc version: v1.1.4-0-g5fd4c4d
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.15.90.1-microsoft-standard-WSL2
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 20
 Total Memory: 15.46GiB
 Name: docker-desktop
 ID: QJKW:RYR5:C3GT:AG5U:EYU3:5MPG:GQMG:FOSN:QNG2:KG7D:UW4N:WIGB
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5000
  127.0.0.0/8
 Live Restore Enabled: false

Docker compose file

version: "3"

services:
  mariadb:
    image: wodby/mariadb:$MARIADB_TAG
    container_name: "${PROJECT_NAME}_mariadb"
    stop_grace_period: 30s
    environment:
      MYSQL_ROOT_PASSWORD: $DB_ROOT_PASSWORD
      MYSQL_DATABASE: $DB_NAME
      MYSQL_USER: $DB_USER
      MYSQL_PASSWORD: $DB_PASSWORD
#    volumes:
#      - ./mariadb-init:/docker-entrypoint-initdb.d # Place init .sql file(s) here.
#      - /path/to/mariadb/data/on/host:/var/lib/mysql # I want to manage volumes manually.

  #  postgres:
  #    image: wodby/postgres:$POSTGRES_TAG
  #    container_name: "${PROJECT_NAME}_postgres"
  #    stop_grace_period: 30s
  #    environment:
  #      POSTGRES_PASSWORD: $DB_PASSWORD
  #      POSTGRES_DB: $DB_NAME
  #      POSTGRES_USER: $DB_USER
  #    volumes:
  #    - ./postgres-init:/docker-entrypoint-initdb.d # Place init file(s) here.
  #    - /path/to/postgres/data/on/host:/var/lib/postgresql/data # I want to manage volumes manually.

  php:
    image: wodby/laravel-php:$PHP_TAG
    container_name: "${PROJECT_NAME}_php"
    environment:
      APP_KEY: $APP_KEY
      LARAVEL_APP_DEBUG: 'true'
      SSMTP_MAILHUB: mailhog:1025
#      SSMTP_MAILHUB: opensmtpd:25
      PHP_SENDMAIL_PATH: '"/usr/bin/dos2unix -u | /usr/sbin/ssmtp -t -f"'
      DB_HOST: $DB_HOST
      DB_USER: $DB_USER
      DB_PASSWORD: $DB_PASSWORD
      DB_NAME: $DB_NAME
      PHP_FPM_USER: wodby
      PHP_FPM_GROUP: wodby
## Read instructions at https://wodby.com/docs/stacks/laravel/local/#xdebug
#      PHP_XDEBUG: 1
#      PHP_XDEBUG_MODE: debug
#      PHP_XDEBUG_MODE: profile
#      PHP_XDEBUG_USE_COMPRESSION: false
#      PHP_IDE_CONFIG: serverName=my-ide
#      PHP_XDEBUG_IDEKEY: "my-ide"
#      PHP_XDEBUG_CLIENT_HOST: 172.17.0.1 # Linux
#      PHP_XDEBUG_CLIENT_HOST: host.docker.internal # Docker 18.03+ Mac/Win
#      PHP_XDEBUG_CLIENT_HOST: 10.0.75.1 # Windows
    volumes:
    - ./:/var/www/html:cached
## Alternative for macOS users: Mutagen https://wodby.com/docs/stacks/laravel/local#docker-for-mac
#    - backend:/var/www/html
## For XHProf and Xdebug profiler traces
#    - files:/mnt/files

#  queue:
#    image: wodby/laravel-php:$PHP_TAG
#    container_name: "${PROJECT_NAME}_queue"
#    environment:
#      SSMTP_MAILHUB: mailhog:1025
#      #      SSMTP_MAILHUB: opensmtpd:25
#      PHP_SENDMAIL_PATH: '"/usr/bin/dos2unix -u | /usr/sbin/ssmtp -t -f"'
#      DB_HOST: $DB_HOST
#      DB_USER: $DB_USER
#      DB_PASSWORD: $DB_PASSWORD
#      DB_NAME: $DB_NAME
#      PHP_FPM_USER: wodby
#      PHP_FPM_GROUP: wodby
#      QUEUE_CONNECTION: redis
#    ## Read instructions at https://wodby.com/docs/stacks/laravel/local/#xdebug
#    #      PHP_XDEBUG: 1
#    #      PHP_XDEBUG_MODE: debug
#    #      PHP_XDEBUG_MODE: profile
#    #      PHP_XDEBUG_USE_COMPRESSION: false
#    #      PHP_IDE_CONFIG: serverName=my-ide
#    #      PHP_XDEBUG_IDEKEY: "my-ide"
#    #      PHP_XDEBUG_CLIENT_HOST: 172.17.0.1 # Linux
#    #      PHP_XDEBUG_CLIENT_HOST: host.docker.internal # Docker 18.03+ Mac/Win
#    #      PHP_XDEBUG_CLIENT_HOST: 10.0.75.1 # Windows
#    command: ["php", "artisan", "queue:listen"]
#    volumes:
#    - ./:/var/www/html:cached
#  ## Alternative for macOS users: Mutagen https://wodby.com/docs/stacks/laravel/local#docker-for-mac
#  #    - backend:/var/www/html
#  ## For XHProf and Xdebug profiler traces
#  #    - files:/mnt/files

  nginx:
    image: wodby/nginx:$NGINX_TAG
    container_name: "${PROJECT_NAME}_nginx"
    depends_on:
    - php
    environment:
      NGINX_STATIC_OPEN_FILE_CACHE: "off"
      NGINX_ERROR_LOG_LEVEL: debug
      NGINX_BACKEND_HOST: php
      NGINX_VHOST_PRESET: php
      NGINX_SERVER_ROOT: /var/www/html/public
    volumes:
    - ./:/var/www/html:cached
## Alternative for macOS users: Mutagen https://wodby.com/docs/stacks/laravel/local#docker-for-mac
#    - backend:/var/www/html
    labels:
    - "traefik.http.routers.${PROJECT_NAME}_nginx.rule=Host(`${PROJECT_BASE_URL}`)"

#  apache:
#    image: wodby/apache:$APACHE_TAG
#    container_name: "${PROJECT_NAME}_apache"
#    depends_on:
#    - php
#    environment:
#      APACHE_LOG_LEVEL: debug
#      APACHE_BACKEND_HOST: php
#      APACHE_VHOST_PRESET: php
#      APACHE_DOCUMENT_ROOT: /var/www/html/public
#    volumes:
#    - ./:/var/www/html:cached
### Alternative for macOS users: Mutagen https://wodby.com/docs/stacks/laravel/local#docker-for-mac
##    - backend:/var/www/html
#    labels:
#    - "traefik.http.routers.${PROJECT_NAME}_apache.rule=Host(`${PROJECT_BASE_URL}`)"

  mailhog:
    image: mailhog/mailhog
    container_name: "${PROJECT_NAME}_mailhog"
    labels:
    - "traefik.http.services.${PROJECT_NAME}_mailhog.loadbalancer.server.port=8025"
    - "traefik.http.routers.${PROJECT_NAME}_mailhog.rule=Host(`mailhog.${PROJECT_BASE_URL}`)"

#  crond:
#    image: wodby/php:$PHP_TAG
#    container_name: "${PROJECT_NAME}_crond"
#    environment:
#      CRONTAB: "0 * * * * echo 'cron test'"
#    command: sudo crond -f -d 0
#    volumes:
#    - ./:/var/www/html:cached
### Alternative for macOS users: Mutagen https://wodby.com/docs/stacks/laravel/local#docker-for-mac
##    - backend:/var/www/html

#  varnish:
#    image: wodby/varnish:$VARNISH_TAG
#    container_name: "${PROJECT_NAME}_varnish"
#    depends_on:
#    - nginx
#    environment:
#      VARNISH_SECRET: secret
#      VARNISH_BACKEND_HOST: nginx
#      VARNISH_BACKEND_PORT: 80
#      VARNISH_ALLOW_UNRESTRICTED_PURGE: 1
#    labels:
#    - "traefik.http.services.${PROJECT_NAME}_varnish.loadbalancer.server.port=6081"
#    - "traefik.http.routers.${PROJECT_NAME}_varnish.rule=Host(`varnish.${PROJECT_BASE_URL}`)"

#  redis:
#    container_name: "${PROJECT_NAME}_redis"
#    image: wodby/redis:$REDIS_TAG

#  adminer:
#    container_name: "${PROJECT_NAME}_adminer"
#    image: wodby/adminer:$ADMINER_TAG
#    environment:
##      # For PostgreSQL:
##      ADMINER_DEFAULT_DB_DRIVER: pgsql
#      ADMINER_DEFAULT_DB_HOST: $DB_HOST
#      ADMINER_DEFAULT_DB_NAME: $DB_NAME
#    labels:
#    - "traefik.http.routers.${PROJECT_NAME}_adminer.rule=Host(`adminer.${PROJECT_BASE_URL}`)"

#  pma:
#    image: phpmyadmin/phpmyadmin
#    container_name: "${PROJECT_NAME}_pma"
#    environment:
#      PMA_HOST: $DB_HOST
#      PMA_USER: $DB_USER
#      PMA_PASSWORD: $DB_PASSWORD
#      PHP_UPLOAD_MAX_FILESIZE: 1G
#      PHP_MAX_INPUT_VARS: 1G
#    labels:
#    - "traefik.http.routers.${PROJECT_NAME}_pma.rule=Host(`pma.${PROJECT_BASE_URL}`)"

#  solr:
#    image: wodby/solr:$SOLR_TAG
#    container_name: "${PROJECT_NAME}_solr"
#    environment:
#      SOLR_HEAP: 1024m
#    labels:
#    - "traefik.http.services.${PROJECT_NAME}_solr.loadbalancer.server.port=8983"
#    - "traefik.http.routers.${PROJECT_NAME}_solr.rule=Host(`solr.${PROJECT_BASE_URL}`)"

#  elasticsearch:
#    image: wodby/elasticsearch:$ELASTICSEARCH_TAG
#    environment:
#      ES_JAVA_OPTS: "-Xms500m -Xmx500m"
#    ulimits:
#      memlock:
#        soft: -1
#        hard: -1

#  kibana:
#    image: wodby/kibana:$KIBANA_TAG
#    depends_on:
#    - elasticsearch
#    labels:
#    - "traefik.http.services.${PROJECT_NAME}_kibana.loadbalancer.server.port=5601"
#    - "traefik.http.routers.${PROJECT_NAME}_kibana.rule=Host(`kibana.${PROJECT_BASE_URL}`)"

#  memcached:
#    container_name: "${PROJECT_NAME}_memcached"
#    image: wodby/memcached:$MEMCACHED_TAG

#  rsyslog:
#    container_name: "${PROJECT_NAME}_rsyslog"
#    image: wodby/rsyslog:$RSYSLOG_TAG

#  athenapdf:
#    image: arachnysdocker/athenapdf-service:$ATHENAPDF_TAG
#    container_name: "${PROJECT_NAME}_athenapdf"
#    environment:
#      WEAVER_AUTH_KEY: weaver-auth-key
#      WEAVER_ATHENA_CMD: "athenapdf -S"
#      WEAVER_MAX_WORKERS: 10
#      WEAVER_MAX_CONVERSION_QUEUE: 50
#      WEAVER_WORKER_TIMEOUT: 90
#      WEAVER_CONVERSION_FALLBACK: "false"

#  node:
#    image: wodby/node:$NODE_TAG
#    container_name: "${PROJECT_NAME}_node"
#    working_dir: /app
#    labels:
#    - "traefik.http.services.${PROJECT_NAME}_node.loadbalancer.server.port=3000"
#    - "traefik.http.routers.${PROJECT_NAME}_node.rule=Host(`node.${PROJECT_BASE_URL}`)"
#    expose:
#    - "3000"
#    volumes:
#    - ./path/to/your/single-page-app:/app
#    command: sh -c 'npm install && npm run start'

#  webgrind:
#    image: wodby/webgrind:$WEBGRIND_TAG
#    environment:
#      WEBGRIND_PROFILER_DIR: /mnt/files/xdebug
#    labels:
#    - "traefik.http.routers.${PROJECT_NAME}_webgrind.rule=Host(`webgrind.${PROJECT_BASE_URL}`)"
#    volumes:
#    - files:/mnt/files
#    - ./:/mnt/codebase:cached

#  opensmtpd:
#    container_name: "${PROJECT_NAME}_opensmtpd"
#    image: wodby/opensmtpd:$OPENSMTPD_TAG

#  xhprof:
#    image: wodby/xhprof:$XHPROF_TAG
#    restart: always
#    volumes:
#    - files:/mnt/files
#    labels:
#    - "traefik.http.routers.${PROJECT_NAME}_xhprof.rule=Host(`xhprof.${PROJECT_BASE_URL}`)"

  traefik:
    image: traefik:v2.0
    container_name: "${PROJECT_NAME}_traefik"
    command: --api.insecure=true --providers.docker
    ports:
    - '8000:80'
#    - '8080:8080' # Dashboard
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock

#x-mutagen:
#  sync:
#    defaults:
#      ignore:
#        vcs: true
#        paths:
#        - .DS_Store
#        - .history
#        - .idea
#    backend:
#      alpha: "."
#      beta: "volume://backend"
#      configurationBeta:
#        permissions:
#          defaultFileMode: 0644
#          defaultDirectoryMode: 0755
#          defaultOwner: "id:501"
#          defaultGroup: "id:20"

#volumes:
## Mutagen for macOS users
#  backend:
## For Xdebug profiler
#  files:
@csandanov
Copy link
Member

docker-compose currently doesn't support using custom names for .env docker/compose#7289

so the best option right now is to rename laravel's .env file and specify it in docker-compose like services.php.env_file: laravel.env

csandanov added a commit that referenced this issue Apr 6, 2023
@schn-mark-plachetta
Copy link

Even when you rename Laravel's .env file the problem persists. Seems related to this line which is copying over .env on init:

https://github.com/wodby/laravel-php/blob/main/init/10_laravel_php.sh#L9

@csandanov
Copy link
Member

csandanov commented May 25, 2023

@schn-mark-plachetta you're right

wodby/laravel-php:0.1.2 has been released, now it generates .env file from template only if it doesn't exist

also, you can try explicitly mounting .env for php service:

  php:
    # ...
    volumes:
    - ./:/var/www/html:cached
    - ./.laravel.env:/var/www/html/.env

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants