Fully custom build commands in compose file
jackmtpt opened this issue · 2 comments
Description
Several of our projects use the feature of MSBuild to generate container images as part of publishing: https://learn.microsoft.com/en-us/dotnet/core/docker/publish-as-container
This means that these projects do not have a Dockerfile, because MSBuild generates the final image itself by adding layer(s) on top of a specified base image that contain the compiled binaries. Typically we would run a command like dotnet publish /t:PublishContainer
to build the container image - MSBuild will automatically tag the image and put it into the cache of the local Docker daemon.
We would like the ability to integrate this into a compose file in a similar way that compose can currently build an image from a Dockerfile if it's not present locally. I'm imagining syntax like the following:
backend:
image: example/app-backend
build:
context: backend
custom_command: dotnet publish /t:PublishContainer
The custom-command
would be executed instead of docker build
using the context directory as the working dir (and likely most if not all other options would be ignored).
Currently the workaround for this is that developers must run dotnet publish
manually first, and then docker compose up
afterwards - this would eliminate that and enable the same simplicity that you get when compose builds from a Dockerfile.
Comparable to #10615 and a few other to request support for third-party build tooling.
I wonder we could support this feature relying service hooks, i.e we could introduce a build
hook, which would run a command responsible to prepare or produce the desired image, before compose trigger a docker build
.
That being said, this would break compose file portability (by depending on a third-party command) 🤨
A pre-build hook could work yeah, as long as the hook can then prevent docker build
from actually getting executed since in the dotnet publish
scenario docker build
will fail because there's no Dockerfile present.
Yes it would introduce a dependency on a third-party command but - at least in the dotnet scenario - anyone who wants to build the image locally after e.g. making a code change is likely to have the required build tools already installed (via their IDE). In fact it would be an intentional choice by the application author to require this because they would not be providing a Dockerfile to build the image the traditional way, so I think that's acceptable.