Skip to content

Ability to pass --env-file argument in docker-compose #273

Closed

Description

@earthslasthope

The issue I'm having is I can't see a way to pass a custom env-file in Visual Studio when debugging my docker-compose project. I can see there is a DockerfileRunEnvironmentFiles property that allows doing this for single projects (docker run) but there is nothing similar for docker-compose. Furthermore, I can't find a documented way to pass any custom options that come after docker-compose before the commands which would take care of this (e.g. docker-compose --env-file my_vars -f docker-compose-custom.yml up).

Are there any options to accomplish this? Can I customise how the docker-compose command gets built?

For your reference I was looking at the documentation here https://docs.microsoft.com/en-us/visualstudio/containers/docker-compose-properties?view=vs-2019

Activity

  1. pratiksanglikar commented on Sep 24, 2020

    @pratiksanglikar
    Contributor

    Hi @tthordarson ,
    Additional arguments to the docker-compose up command can be passed through DockerComposeUpArguments property.
    That being said, I tried --env-file with DockerComposeUpArguments, but --env-file needs to be passed before up as opposed to after up.
    I am investigating how this could be achieved.

  2. syedhassaanahmed commented on Jun 18, 2021

    @syedhassaanahmed
    Member

    Pratik Sanglikar (@pratiksanglikar) Any update on the investigation about passing the custom env file as argument to docker compose up ?

  3. pratiksanglikar commented on Jun 22, 2021

    @pratiksanglikar
    Contributor

    Hassaan Ahmed (@syedhassaanahmed), it is an item on our backlog, but with the current priorities, there is no specific date when we can get to it.

  4. CriggerMarg commented on Aug 12, 2022

    @CriggerMarg
  5. NCarlsonMSFT commented on Aug 15, 2022

    @NCarlsonMSFT
    Member

    Anton Shakalo (@CriggerMarg) this remains on the backlog (now assigned to me) and is actually getting fairly close to the top.

  6. ludovicasa commented on Dec 14, 2022

    @ludovicasa

    Hello,
    any news on this one ?

    Currently the command generated by VS adds the "--env-file" option after the "up" command:
    up -d --env-file .env.dev

    resulting in an error:

    C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Sdks\Microsoft.Docker.Sdk\build\Microsoft.VisualStudio.Docker.Compose.targets(402,5): error DT1001: unknown flag: --env-file
    C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Sdks\Microsoft.Docker.Sdk\build\Microsoft.VisualStudio.Docker.Compose.targets(402,5): error DT1001: If the error persists, try restarting Docker Desktop.
    

    Maybe there is a workaround ?

  7. NCarlsonMSFT commented on Dec 14, 2022

    @NCarlsonMSFT
    Member

    Sorry for the delay, this has now reached the top of the backlog and a fix is out for review. I still don't have a timeline for when the fix will be available, but it is in progress.

  8. raulidavid commented on Jan 28, 2023

    @raulidavid

    Please, friend Nathan Carlson (@NCarlsonMSFT) , let me know when it's ready. I'm having the same problem. Regards

  9. NCarlsonMSFT commented on Jan 31, 2023

    @NCarlsonMSFT
    Member

    Raúl Flores (@raulidavid) this currently available in the preview channel 17.5 Preview 4

  10. raulidavid commented on Jan 31, 2023

    @raulidavid

    Thanks Nathan Carlson (@NCarlsonMSFT) Test on visual studio 2022 preview 4 but still getting the same message unknown flag: --env-file adding this <DockerComposeBuildArguments>--env-file .env</DockerComposeBuildArguments>

  11. NCarlsonMSFT commented on Jan 31, 2023

    @NCarlsonMSFT
    Member

    Sorry Raúl Flores (@raulidavid), I was flitting through too many things yesterday and omitted telling you that there is a new MSBuildProperty to support this:
    <DockerComposeEnvFilePath>myawesomefilename.env</DockerComposeEnvFilePath>

  12. raulidavid commented on Feb 1, 2023

    @raulidavid

    thanks Nathan Carlson (@NCarlsonMSFT) now it's working!!

  13. NCarlsonMSFT commented on Feb 6, 2023

    @NCarlsonMSFT
    Member

    Anton Shakalo (@CriggerMarg) I've added updating the docs to the backlog.

  14. davhdavh commented on May 5, 2023

    @davhdavh

    It works great, but would be nice if it was also documented :)

  15. fiveisprime commented on Jun 21, 2024

    @fiveisprime
    Member

    Closing this as fixed. The documentation has also been updated to include the DockerComposeEnvFilePath property

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions