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

Specify Working Directory for .env file #43

Open
zogot opened this issue Jan 14, 2017 · 6 comments
Open

Specify Working Directory for .env file #43

zogot opened this issue Jan 14, 2017 · 6 comments
Labels

Comments

@zogot
Copy link

zogot commented Jan 14, 2017

Since docker-compose allows specifying a .env file to be loaded, and its dependent on the running location of docker-compose, being able to specify where we are running docker-compose will help a lot.

https://docs.docker.com/compose/env-file/

@zogot
Copy link
Author

zogot commented Jan 14, 2017

For anyone that may want to know how to solve it currently. The docker commands are run from /home/vagrant.

I just opted to copy the .env file with an inline config.vm.provision "shell"

@leighmcculloch
Copy link
Owner

The docker-compose up command runs in the default working directory, which vagrant sets as /vagrant. I don't see anyway of changing this with the built-in Vagrantfile options, but I'm 👍 for adding a working_directory parameter which is where the commands are run from.

@zogot: Did you want to take a stab at adding the feature?

@leighmcculloch
Copy link
Owner

@zogot: I took another look at adding this but then discovered Vagrant already has a feature for changing the working directory. If you set the VAGRANT_CWD environment variable it will change the working directory to there.

Ref: https://www.vagrantup.com/docs/other/environmental-variables.html#vagrant_cwd

Let me know if that solves it for you.

@paul-corda
Copy link

paul-corda commented Sep 25, 2017

I've gone ahead and used this great gist here:
https://gist.github.com/jowave/9f9059cd79bd8e59398ac5f7fe7b6218

Building my hash based on where the .env file is located in my vagrant host & then just passing it as described in: #33

@marceloverdijk
Copy link

marceloverdijk commented Feb 7, 2018

@paul-corda that gist didn't worked for me.
Using 28: compose_env = Hash[*File.read(".env").split(/[=\n]+/)] gives me the following error:
Vagrantfile:28:in []': odd number of arguments for Hash (ArgumentError)

Is there another way to use the .env file with Vagrant/Docker-compose?

UPDATE

I changed it to:

  compose_env = Hash.new
  if File.file?(".env")
    array = File.read(".env").split("\n")
    array.each do |e|
      unless e.start_with?("#")
        var = e.split("=")
        compose_env[var[0]] = var[1]
      end
    end
  end

which seems to work.

@paul-corda
Copy link

paul-corda commented Feb 15, 2018

@marceloverdijk Seems to be an issue with how it handles commented lines?
Glad you've found a fix for your issue though! :)

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

No branches or pull requests

4 participants