Dockertools: Multiple docker-compose.yml files

Created on 19 Jun 2018  路  7Comments  路  Source: microsoft/DockerTools

Hi all, I have 2 issues.
The first one: I want to have multiple custom named docker-compose files in the .dcproj, for example:
<ItemGroup> <None Include="dev.env" /> <None Include="docker-compose.first.yml"> <DependentUpon>docker-compose.yml</DependentUpon> </None> <None Include="docker-compose.second.yml"> <DependentUpon>docker-compose.yml</DependentUpon> </None> <None Include="docker-compose.third.yml"> <DependentUpon>docker-compose.yml</DependentUpon> </None> </ItemGroup>

and this should run: docker-compose -f docker-compose.yml -f docker-compose.first.yml -f docker-compose.second.yml -f docker-compose.third.yml up

The second one: If I have docker-compose.yml in not the same folder as docker-compose.dcproj, the tool can't resolve it. Example:

<None Include="docker-compose.override.yml"> <DependentUpon>../docker-compose.yml</DependentUpon> </None>

I need to have two or more dcproj files which share one main docker-compose.yml file.
Maybe I'm not doing everything right. If those issues are by design, do you plan for future support.
Thanks.

Most helpful comment

In VS 15.9 Preview 4, we added a couple of improvements in docker-compose based projects, where the users can:

  • Define the base name for the docker-compose.yml and docker-compose.override.yml files:
    The base name corresponds to the first section of the yml file name such as what is in bold above.
    So by default, the base name is "docker-compose" however now the user has the ability to change that by defining a property in the dc-project: <DockerComposeBaseFilePath>mycustomdockercompose</DockerComposeBaseFilePath>
As the name implies, it can also be a relative path:
`<DockerComposeBaseFilePath>..\mycustomdockercompose</DockerComposeBaseFilePath>`
OR
`<DockerComposeBaseFilePath>DockerComposeFiles\mycustomdockercompose</DockerComposeBaseFilePath>`

Please note that if you decide to move the docker-compose yml file, then you'll have to make sure the build context for each service is set correctly to the solution folder relative to the yml file location. That should be more clear in the below example.
  • Add more docker-compose files to be included in the project:
    Users can now add more docker-compose files as part of the build/run commands that the tooling performs. For instance, here's an example for adding "mydockercompose1.yml" and "mydockercompose2.yml" files (relative paths could be used as well):
    <AdditionalComposeFilePaths>mydockercompose1.yml;..\mydockercompose2.yml</AdditionalComposeFilePaths>

    The order of execution in any docker-compose command will be as follows:
    {docker-compose main file} {docker-compose override file} [Additional compose files]* {generated files}

Here's an example dc-proj file that utilizes both properties above:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" Sdk="Microsoft.Docker.Sdk">
  <PropertyGroup Label="Globals">
    <ProjectVersion>2.1</ProjectVersion>
    <DockerTargetOS>Windows</DockerTargetOS>
    <ProjectGuid>154022c1-8014-4e9d-bd78-6ff46670ffa4</ProjectGuid>
    <DockerLaunchAction>LaunchBrowser</DockerLaunchAction>
    <DockerServiceUrl>{Scheme}://{ServiceIPAddress}{ServicePort}</DockerServiceUrl>
    <DockerServiceName>webapplication1</DockerServiceName>
    <DockerComposeBaseFilePath>DockerComposeFiles\mydockercompose</DockerComposeBaseFilePath>
    <AdditionalComposeFilePaths>AdditionalComposeFiles\myadditionalcompose.yml</AdditionalComposeFilePaths>
  </PropertyGroup>
  <ItemGroup>
    <None Include="DockerComposeFiles\mydockercompose.override.yml">
      <DependentUpon>DockerComposeFiles\mydockercompose.yml</DependentUpon>
    </None>
    <None Include="DockerComposeFiles\mydockercompose.yml" />
    <None Include=".dockerignore" />
  </ItemGroup>
</Project>

And here's the corresponding mydockercompose.yml file:

version: '3.4'

services:
  webapplication1:
    image: ${DOCKER_REGISTRY-}webapplication1
    build:
      context: ..
      dockerfile: WebApplication1\Dockerfile

All this info should be added to our docs soon as well, however please let me know if anything is unclear and I'll be happy to help.

All 7 comments

I've noticed that visual studio will run docker-compose.yml docker-compose.override.yml which is a docker compose convention. They also tack on some stuff from the obj folder. I think your request is still valid. I would like to see docker compose files be configurable per build configuration so debug and release targets can modify the resulting containers.

Well for the build configurations I've tried to add to the .dcproj docker-compose.vs.debug.yml and it works. I think the same works for docker-compose.vs.prod.yml but again is strict convention. I think it should be better if the tool uses a pattern for matching compose files like "docker-compose.*.yml".

PS: Maybe the tool should be open sourced so we can contribute to it.

I'm also having this problem. Did anyone find a workaround?

Thank you

This is a big problem, at least we should be able to rename docker-compose.yml to something we like or makes more sense and not hardcode this.

Would be great to have this fixed.

In VS 15.9 Preview 4, we added a couple of improvements in docker-compose based projects, where the users can:

  • Define the base name for the docker-compose.yml and docker-compose.override.yml files:
    The base name corresponds to the first section of the yml file name such as what is in bold above.
    So by default, the base name is "docker-compose" however now the user has the ability to change that by defining a property in the dc-project: <DockerComposeBaseFilePath>mycustomdockercompose</DockerComposeBaseFilePath>
As the name implies, it can also be a relative path:
`<DockerComposeBaseFilePath>..\mycustomdockercompose</DockerComposeBaseFilePath>`
OR
`<DockerComposeBaseFilePath>DockerComposeFiles\mycustomdockercompose</DockerComposeBaseFilePath>`

Please note that if you decide to move the docker-compose yml file, then you'll have to make sure the build context for each service is set correctly to the solution folder relative to the yml file location. That should be more clear in the below example.
  • Add more docker-compose files to be included in the project:
    Users can now add more docker-compose files as part of the build/run commands that the tooling performs. For instance, here's an example for adding "mydockercompose1.yml" and "mydockercompose2.yml" files (relative paths could be used as well):
    <AdditionalComposeFilePaths>mydockercompose1.yml;..\mydockercompose2.yml</AdditionalComposeFilePaths>

    The order of execution in any docker-compose command will be as follows:
    {docker-compose main file} {docker-compose override file} [Additional compose files]* {generated files}

Here's an example dc-proj file that utilizes both properties above:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" Sdk="Microsoft.Docker.Sdk">
  <PropertyGroup Label="Globals">
    <ProjectVersion>2.1</ProjectVersion>
    <DockerTargetOS>Windows</DockerTargetOS>
    <ProjectGuid>154022c1-8014-4e9d-bd78-6ff46670ffa4</ProjectGuid>
    <DockerLaunchAction>LaunchBrowser</DockerLaunchAction>
    <DockerServiceUrl>{Scheme}://{ServiceIPAddress}{ServicePort}</DockerServiceUrl>
    <DockerServiceName>webapplication1</DockerServiceName>
    <DockerComposeBaseFilePath>DockerComposeFiles\mydockercompose</DockerComposeBaseFilePath>
    <AdditionalComposeFilePaths>AdditionalComposeFiles\myadditionalcompose.yml</AdditionalComposeFilePaths>
  </PropertyGroup>
  <ItemGroup>
    <None Include="DockerComposeFiles\mydockercompose.override.yml">
      <DependentUpon>DockerComposeFiles\mydockercompose.yml</DependentUpon>
    </None>
    <None Include="DockerComposeFiles\mydockercompose.yml" />
    <None Include=".dockerignore" />
  </ItemGroup>
</Project>

And here's the corresponding mydockercompose.yml file:

version: '3.4'

services:
  webapplication1:
    image: ${DOCKER_REGISTRY-}webapplication1
    build:
      context: ..
      dockerfile: WebApplication1\Dockerfile

All this info should be added to our docs soon as well, however please let me know if anything is unclear and I'll be happy to help.

seems to working in 15.9

thanks @joetherod for the confirmation!

Was this page helpful?
0 / 5 - 0 ratings