sdk-container-builds icon indicating copy to clipboard operation
sdk-container-builds copied to clipboard

Add a target to generate the equivalent Dockerfile for a given project

Open baronfel opened this issue 3 years ago • 10 comments

As part of the 'grow up' story for the tool, it would be great if there was a way to scaffold out the Dockerfile equivalent of what we do in the Task. That would give folks an opinionated base to start any customizations from.

baronfel avatar Aug 26 '22 21:08 baronfel

This is an amazing suggestion. There are some environments (including Cloud Shell) where you don't have an active Docker host. Being able to generate a Dockerfile enables us to build the container image using tools like Azure Container Registry and az acr build.

Today, the tmds/build-image project gets close, but it has some extra commands that require BuildKit.

seesharprun avatar Aug 27 '22 15:08 seesharprun

@tmds' project is awesome, by the way :) I'm very excited to see so much containerization energy in the .NET ecosystem right now!

Integration with other tools is a great additional use case for this issue. Docker Compose for example doesn't know anything about MSBuild and so cannot reasonably publish and use your container inside docker compose up. If we could emit a Dockerfile (even if it was in gitignore and never commited) that makes it easy to integrate.

baronfel avatar Aug 27 '22 17:08 baronfel

Today, the tmds/build-image project gets close, but it has some extra commands that require BuildKit.

@seesharprun if you create a ticket at https://github.com/tmds/build-image/issues I'll look into it.

tmds avatar Aug 28 '22 08:08 tmds

This a helpful thing, if we have an option for exporting docker file beside of publish a docker image

mehdihadeli avatar Nov 28 '22 17:11 mehdihadeli

@mehdihadeli are you interested in potentially contributing it? I'd be happy to walk you through the process.

baronfel avatar Nov 28 '22 17:11 baronfel

tmds/build-image project gets close, but it has some extra commands that require BuildKit.

I've made some improvements to https://github.com/tmds/build-image. By specifying the --portable flag you can create a Dockerfile that doesn't depend on BuildKit. I've also aligned the property names with those used by sdk-container-builds.

dotnet tool install -g dotnet-build-image
dotnet new web -o web
cd web
dotnet build-image --portable --as-file Dockerfile

tmds avatar Nov 30 '22 13:11 tmds

tmds/build-image project gets close, but it has some extra commands that require BuildKit.

I've made some improvements to https://github.com/tmds/build-image. By specifying the --portable flag you can create a Dockerfile that doesn't depend on BuildKit. I've also aligned the property names with those used by sdk-container-builds.


dotnet tool install -g dotnet-build-image

dotnet new web -o web

cd web

dotnet build-image --portable --as-file Dockerfile

This looks to be exactly what I'm after. Will give it a try

clarkezone avatar Apr 05 '23 13:04 clarkezone

Hello there, I was looking for a possibility to integrate container creation using dotnet publish with docker compose. So as it seems impossible, we will have to stay with the manual Dockerfiles creation 😞 Honestly I'm surprised that emitting Dockerfile wasn't the first step before abstracting it away by hiding container creation details under the hood. Dependency on the docker engine is currently obvious anyway (what is a separate issue...).

baterja avatar Jun 14 '24 12:06 baterja

Emitting Dockerfiles is hard to do with 100% fidelity due to things like NuGet authentication. In many ways, directly creating the image tarballs and json was the easier thing to do! In addition, even if we did do Dockerfiles, you wouldn't get great docker-compose integration - the compose file tooling is not easily extensible (you have to write and distribute a buildx plugin, and that is a LARGE amount of work) and so you wouldn't be able to integrate the dotnet CLI nicely with the compose management process.

What we did aligns with how the JIB and ko communities for Java and go integrate with compose, so I'm pretty satisfied with that currently.

Having said that, we do want to do Dockerfile generation, but we don't have an internal customer really pushing for that development, and we've been focusing on workflows that support other team efforts like Aspire. The best way to get this functionality added would be to send us a PR - we love working with community members to make the SDK Container publishing better for everyone!

baronfel avatar Jun 15 '24 01:06 baronfel

Thanks for your comment @baronfel. I'll take a look at Aspire. Maybe instead of trying to make docker compose work with dotnet publish going the other way and replacing compose with Aspire will be easier to achieve.

baterja avatar Jun 16 '24 20:06 baterja