Skip to content

Commit c5f5418

Browse files
authored
Merge pull request #5757 from ghogen/docker-compose-props
Example of using DockerComposeBaseFilePath
2 parents 3a19319 + 48923df commit c5f5418

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

docs/containers/docker-compose-properties.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,46 @@ The following table shows the MSBuild properties available for Docker Compose pr
4141
|DockerServiceUrl| dcproj | The URL to use when launching the browser. Valid replacement tokens are "{ServiceIPAddress}", "{ServicePort}", and "{Scheme}". For example: {Scheme}://{ServiceIPAddress}:{ServicePort}|-|
4242
|DockerTargetOS| dcproj | The target OS used when building the Docker image.|-|
4343

44+
## Example
45+
46+
If you change the location of the docker compose files, by setting `DockerComposeBaseFilePath` to a relative path, then you also need to make sure that the build context is changed so that it references the solution folder. For example, if your docker compose file is a folder called *DockerComposeFiles*, then docker compose file should set the build context to ".." or "../..", depending on where it is relative to the solution folder.
47+
48+
```xml
49+
<?xml version="1.0" encoding="utf-8"?>
50+
<Project ToolsVersion="15.0" Sdk="Microsoft.Docker.Sdk">
51+
<PropertyGroup Label="Globals">
52+
<ProjectVersion>2.1</ProjectVersion>
53+
<DockerTargetOS>Windows</DockerTargetOS>
54+
<ProjectGuid>154022c1-8014-4e9d-bd78-6ff46670ffa4</ProjectGuid>
55+
<DockerLaunchAction>LaunchBrowser</DockerLaunchAction>
56+
<DockerServiceUrl>{Scheme}://{ServiceIPAddress}{ServicePort}</DockerServiceUrl>
57+
<DockerServiceName>webapplication1</DockerServiceName>
58+
<DockerComposeBaseFilePath>DockerComposeFiles\mydockercompose</DockerComposeBaseFilePath>
59+
<AdditionalComposeFilePaths>AdditionalComposeFiles\myadditionalcompose.yml</AdditionalComposeFilePaths>
60+
</PropertyGroup>
61+
<ItemGroup>
62+
<None Include="DockerComposeFiles\mydockercompose.override.yml">
63+
<DependentUpon>DockerComposeFiles\mydockercompose.yml</DependentUpon>
64+
</None>
65+
<None Include="DockerComposeFiles\mydockercompose.yml" />
66+
<None Include=".dockerignore" />
67+
</ItemGroup>
68+
</Project>
69+
```
70+
71+
The *mydockercompose.yml* file should look like this, with the build context set to the relative path of the solution folder (in this case, `..`).
72+
73+
```yml
74+
version: '3.4'
75+
76+
services:
77+
webapplication1:
78+
image: ${DOCKER_REGISTRY-}webapplication1
79+
build:
80+
context: ..
81+
dockerfile: WebApplication1\Dockerfile
82+
```
83+
4484
> [!NOTE]
4585
> DockerComposeBuildArguments, DockerComposeDownArguments, and DockerComposeUpArguments are new in Visual Studio 2019 version 16.3.
4686

0 commit comments

Comments
 (0)