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

".env" not taken into account #52

Closed
mbrodala opened this issue Oct 10, 2018 · 6 comments
Closed

".env" not taken into account #52

mbrodala opened this issue Oct 10, 2018 · 6 comments
Labels

Comments

@mbrodala
Copy link

mbrodala commented Oct 10, 2018

We noticed that our local .env file is not used by docker-compose which is used to set various options.

I assume that's becaues docker-compose is executed in the default login directory (e.g. /home/vagrant) instead of the directory of the .env file. In our case that would be /vagrant where the Compose files are located too.

Would it be possible to add an option to switch the working directory for the docker-compose command?

This could be related to #43.

@leighmcculloch
Copy link
Owner

Can you share the directory structure of where your .env office is located?

@mbrodala
Copy link
Author

mbrodala commented Oct 10, 2018

Everything is toplevel:

.env
docker-compose.yml
Vagrantfile
...

The Vagrantfile then looks accordingly:

  config.vm.provision "app",
    type: "docker_compose",
    compose_version: "1.22.0",
    yml: "/vagrant/docker-compose.yml",
    env: {
      # I'd like to get rid of this
    },
    run: "always"

I also noticed that yml always needs to use absolute paths which would be obsolete if one could set a working directory here.

@leighmcculloch
Copy link
Owner

🤔 That's a good point. If we supported a working directory it would make working with this a lot easier. @mbrodala Are you up for taking a stab at adding support for this and opening a PR?

@mbrodala
Copy link
Author

I'd love to but unfortunately I have limited time ATM. :-/

@mbrodala
Copy link
Author

mbrodala commented Oct 22, 2018

As a workaround we now use a setup like this:

  config.vm.provision :docker_compose,
    compose_version: "1.22.0"

  config.vm.provision "app",
    type: "shell",
    keep_color: true,
    privileged: false,
    run: "always",
    inline: <<-SCRIPT
      cd /vagrant
      docker-compose up --detach
    SCRIPT

This has many advantages:

  1. The .env file is loaded by Docker Compose since we switch the working directory.
  2. We can execute as regular user instead of root, this is useful if you need to manually invoke Docker Compose through vagrant ssh at some point.
  3. Output colors can be rendered as is.

@leighmcculloch
Copy link
Owner

This is a duplicate of #43, let's track there.

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

2 participants