microsoft / DockerTools

Tools For Docker, including Visual Studio Provisioning and Publishing
Other
173 stars 26 forks source link

Relative paths in generated dockerfile appear to be incorrect #408

Open amcasey opened 7 months ago

amcasey commented 7 months ago
  1. Create a new console app in VS
  2. Right-click on the project and select Add > Docker Support
  3. Open the resulting dockerfile

Expected: paths are relative to the folder containing the dockerfile (i.e. the project folder). Actual: paths are relative to the parent folder (i.e. the solution folder).

Was https://github.com/dotnet/aspnetcore/issues/52092

I'm on 17.9.0 Preview 2.0 [34305.10.main], but the OP was on 17.8.0.

patverb commented 7 months ago

@amcasey the paths being relative to the solution isn't a bug in itself. But if it isn't building properly with those then it is a bug.

@LukasKubicek looking at your example I think I might have an idea what is going wrong.

By default, we scaffold paths relative to the solution not the project as intended. With that we imply the build context is ... In your project did you have <DockerfileContext>.</DockerfileContext> set and manually change those dockerfile paths in 7.0? We don't handle scaffolding with a context set very well.

amammes commented 5 months ago

I am on 17.8.5 with .Net 8.0.1. I had to add <DockerfileContext>..</DockerfileContext> to my pubxml and this solved the problem for me.

NCarlsonMSFT commented 5 months ago

@amammes It is not recommended to set DockerfileContext in your pubxml, that should be set in the main project. @amcasey I just checked, the fix for scaffolding with DockerfileContext already set is available in 17.9.0 Preview 3.0

vanhoutenbos commented 3 months ago

I used these steps as well and when running docker build from the project folder it fails. When running docker build -f <FOLDER>/dockerfile from the solution location it works.