11

Let's say I have a cross-platform environment,

my app is deployed twice - once on windows container and one on a Linux container,

In addition, I have a DB container (Linux).

Can I use docker compose to build those 3 services?

I think not - because the images I use are built for a certain os type.

Am I right? and maybe I am wrong and there is a workaround for this?

Shahar Hamuzim Rajuan
  • 5,610
  • 9
  • 53
  • 91
  • only using a `docker-compose` file it would not be possible, because you can't run images for Windows and Linux in the same machine, what could be possible of a solution is to use `docker-machine` to create a linux virtual machine, or something like that, but in any way, would you not be able to link then by docker or things like that... you would have to use a network outside docker to it – Lucas dos Santos Abreu Mar 08 '17 at 00:31
  • 1
    this post doesn't answer the question but should prove useful: https://blog.codeship.com/cross-platform-docker-development-environment/ – wallismark Mar 08 '17 at 00:54

1 Answers1

19

Compose files using version 2.4 support the platform options, which allows for specifying the platform of the service.

platform: osx
platform: windows/amd64
platform: linux/arm64/v8

https://github.com/docker/docker.github.io/blob/master/compose/compose-file/compose-file-v2.md#platform

It should be noted that the platform option is not supported on v3 compose files.

A more in-depth explanation can be found here: https://devblogs.microsoft.com/premier-developer/mixing-windows-and-linux-containers-with-docker-compose/

Devin Turner
  • 206
  • 3
  • 6
  • 3
    Unfortunately, the platform-option is no longer part of docker-compose and the functionality is afaik only supported in the deprecated lcow docker-for-windows implementation. As this topic is still under construction and the documentation is contradictory, please check the latest github issues on this. – Arman Jul 27 '21 at 10:33
  • 1
    It looks like buildx is the way to go now for building cross platfrom from docker-compose files. `docker buildx bake --push --set *.platform=linux/amd64,linux/arm64` See https://stackoverflow.com/a/64563302/758542 – BenCaldwell Mar 24 '22 at 11:49
  • platform option seems to be valid for me in the latest version. My problem is if I can define a variable (i.e in a file or environment) to take the value from there so every developer can set it's own value – Carlos de Luna Saenz Jun 01 '22 at 00:42