mrutyunjay
mrutyunjay

Reputation: 8350

Can I build (not run) a Windows Docker image from a Linux host?

I am new to Docker and container technologies in general so sorry if this is a naive question. Would it possible to just build (not run!) a Windows Docker image from a Linux machine from a Dockerfile?

Upvotes: 1

Views: 5530

Answers (1)

David Maze
David Maze

Reputation: 159865

For the most part, no, it's not.

The real technical problem you'll run into is that it's almost impossible to build an image without RUN steps in the Dockerfile. These do, internally, create containers and run them, and you can't run a Windows container without a Windows host. (Where you can apparently run Linux containers on non-Linux hosts, there's either a layer like WSL or a Linux virtual machine involved.)

If you could build an image without RUNning anything it might be possible via the Dockerfile FROM --platform=windows/amd64 option, but again, you'd be very limited in what you could actually do.

I could imagine wanting this in a couple of specific scenarios. You'd have to do all of the setup in a platform-independent way outside the container. A Java application, for example, can be fully compiled to a portable .jar file and then COPYed into the final image without RUNning anything. I can also imagine a setup building a cross-compiler in an earlier Dockerfile stage (and this is often a pretty hairy exercise) and then COPYing a cross-compiled binary into a Windows image. It might be easier to just run Linux images on Windows via WSL, though.

Upvotes: 5

Related Questions