简体   繁体   English

docker-compose:.env路径问题

[英]docker-compose : Issue with .env path

I'm trying to run a dockerized project which is deployed with Capistrano 我正在尝试运行一个与Capistrano一起部署的dockerized项目

My application is located within /opt/hosting/my-project directory with the following structure : 我的应用程序位于/opt/hosting/my-project目录中,具有以下结构:

/opt/hosting/my-project
    /current -> releases/201704251234/
    /releases/201704251234/
    /repo/
    revisions.log
    /shared/

Currently, what I'm trying to do is simply : 目前,我要做的只是:

cd /opt/hosting/my-project/current
docker-compose -f docker-compose-production.yml up -d

This fails with the following error : 此操作失败,并显示以下错误:

ERROR: Couldn't find env file: /opt/hosting/my-project/shared/.env

This is the content of my docker-compose-production.yml 这是我的docker-compose-production.yml的内容

version: "2"

services:
    app:
        build: ./
        container_name: myproject_app
        env_file:
            - /opt/hosting/my-project/shared/.env
        expose:
            - 9000
        volumes: 
            - /opt/hosting/my-project/:/opt/hosting

The .env file needed exists, is readable and doesn't seem to contain any error. 所需的.env文件存在,可读且似乎不包含任何错误。 Here is its content : 这是它的内容:

COMPOSE_PROJECT_NAME=myproject

My docker-compose -v : 我的docker-compose -v:

docker-compose version 1.9.0, build 2585387

Does anyone have an idea on why this is failing ? 有没有人知道为什么会失败?

Cheers ! 干杯!

Ok so after many tries, I've managed to start my application. 好的,经过多次尝试,我已经成功启动了我的应用程序。

What I've tried to do is : 我试图做的是:

  1. Symlinking my .env files in current directory using Capistrano's feature "Linked files" : /current/.env -> ../../shared/.env Unfortunately this failed as docker-compose doesn't seem to find files or folders that are not within directory where it is executed. 使用Capistrano的功能“链接文件”将当前目录中的.env文件进行符号链接:/current/.env - > ../../shared / .env不幸的是,由于docker-compose似乎找不到文件或文件夹,不在执行它的目录中。

  2. Removing .env linked file from Capistrano config, and manually copying it through a custom Capistrano task. 从Capistrano配置中删除.env链接文件,并通过自定义Capistrano任务手动复制它。

     namespace :env_file do desc "Copy shared .env file" task :copy do on roles(:docker) do within current_path do execute "cp #{shared_path}/.env #{current_path}/.env" end end end end 

The last solution worked and I'm currently using this one for my deployments. 最后一个解决方案有效,我目前正在使用这个解决方案进行部署。 I'll post updates on this issue if I found new problems or improvements. 如果我发现新问题或改进,我会发布有关此问题的更新。

However, is it normal that docker-compose fails using symlinked .env files ? 但是,使用符号链接的.env文件,docker-compose失败是正常的吗?

Cheers 干杯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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