microsoft / microsoft/vscode-remote-release

Remote Containers - Allow to specify --project-directory for docker-compose

Open
#2,323 1 comment 13 reactions 1 assignee View on GitHub

@chrmarti is already working on this.

Since Feb 11, 2020.

containers feature-request plan-review
Dominant language
Dockerfile
Stars
4.2k
Forks
470
Avg merge
1d 1h
Merged PRs (30d)
1

Description

Hi, I like the idea of Remote - Containers. I'm making examples to understand and see how things work with this extension.

I've tried following the steps with Connecting to Multiple Containers at Once, with my own twists where I tried to use a shared .env file.

The Problem

I have this structure:

  • .docker
  • WebApi
    • .devcontainer.json
    • ... Other source code files
  • WebApp
    • .devcontainer.json
    • ... Other source code files
  • .env
  • docker-compose.base.yml
  • docker-compose.devcontainer.yml
  • docker-compose.release.yml

With the remote - containers extension, if you follow the official instructions here, where you'd use the command Remote-Containers: Open Folder in Container..., it won't actually work and would just error out. The problem is it'll open the folder where the .devcontainer.json file resides. The docker-compose command's working directory would also be where this .devcontainer.json file resides.

The implications of this is it'll try to find and use the .env file from the directory where the .devcontainer.json file resides (which of course, doesn't exists). As it doesn't exist in that directory, the .env file isn't used, meaning the environment variables doesn't get imported, causing the extension to fail.

To reproduce this issue, you can clone my example repo, then remove the two .env (i.e. WebApp/.env & WebApi/.env) files, and then follow the README instructions.

Workaround

Thus, currently the only way to get it to work is you'll need to copy your .env file to be where the .devcontainer.json file resides. That is, you'd have the below structure where you .env file is duplicated.

  • .docker
  • WebApi
    • .devcontainer.json
    • .env
    • ... Other source code files
  • WebApp
    • .devcontainer.json
    • .env
    • ... Other source code files
  • docker-compose.base.yml
  • docker-compose.devcontainer.yml
  • docker-compose.release.yml

This isn't really an ideal solution as you'd duplicate the .env file multiple times, needing to maintain all of them.

To reproduce this workaround, you can clone my example repo and then follow the README instructions.

Possible Solution

This can be resolved if the extension lets us somehow specify the option --project-directory for docker-compose, perhaps in the .devcontainer.

For more information on --project-directory, see:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.