microsoft / vscode-remote-release

Visual Studio Code Remote Development: Open any folder in WSL, in a Docker container, or on a remote machine using SSH and take advantage of VS Code's full feature set.
https://aka.ms/vscode-remote
Other
3.69k stars 299 forks source link

Remote Containers performs 'docker-compose config' differently for different Compose versions #6893

Open MartinsSmirnovs opened 2 years ago

MartinsSmirnovs commented 2 years ago

I have moved to Docker Compose V2 and now Remote Containers fail to start my services using docker-compose (see Logs). The issue looks similar to #5992, however turns out that the root cause is different. Before remote Containers starts services, it performs docker-compose config to check that compose files are valid. If we use example repo from "Steps to reproduce" section and run docker-compose config on it, the command will be executed successfully with both Compose V1 and Compose V2, but if we let Remote Containers do it, it will be successful with Compose V1 only. The reason for failure is here:

    volumes:
      - vscode-server:/home/posthelp/.vscode-server
      - type: bind
        # For Compose V1
        source: $PWD
        # For Compose V2
        # source: ${PWD-/home}
        target: /code

With Compose V2, Remote Containers docker-compose config fails because it fails to expand PWD environment variable. There is no such error when we perform the command manually, because, unlike Remote Containers which executes passed command directly without a shell, bash expands the variable and we get expected result. As a workaround we can use Compose default variable substitution as can be seen in commented line under #For Compose V2. My guess is that Remote Containers executes commands for Compose V1 and V2 differently, which makes inconsistent results and problems like this that are difficult to debug.

Steps to Reproduce:

  1. Clone example repo https://github.com/MartinsSmirnovs/vscode-compose-example
  2. Open with Visual Studio Code
  3. Ctrl+Shift+P
  4. >Remote-Containers: Open Folder in Container
  5. Select current directory when prompt opens
chrmarti commented 2 years ago

Can you use . instead? You are right, PWD is set by the shell.

MartinsSmirnovs commented 2 years ago

You are correct, for this particular case . could work instead of PWD, however note that difference between these two is that . is relative path to file where it is located, but PWD is absolute path to directory from which you call command. I have a project where I have two Compose files - one in same directory from which I call Compose command and second one is buried under some nested directories. The second file needs PWD, because it needs path from where the command was called, not to itself.

vscodenpa commented 2 years ago

This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 10 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

vscodenpa commented 2 years ago

:slightly_smiling_face: This feature request received a sufficient number of community upvotes and we moved it to our backlog. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!