marymk
marymk

Reputation: 69

Mixing Windows and Linux containers via docker-compose on a Windows host

I'm facing problems trying to mix Windows and Linux containers via docker-compose on a Windows host as demonstrated in https://devblogs.microsoft.com/premier-developer/mixing-windows-and-linux-containers-with-docker-compose/.

I cloned the original repository of the article (https://github.com/RandyPatterson/DockerComposeMultiPlatform) and already replaced each outdated base image from the Dockerfiles with the new links, you can see all relevant files below. I can get it to run manually by first switching to the Linux daemon, spinning up a container for the API, then switching to the Windows daemon and spinning up a container for the web app.

According to https://stackoverflow.com/a/72260359, docker-compose should also do this, including building it for the respective platform and when I run docker-compose up -d on the Windows daemon, it first starts fine by pulling the Linux images for the ApiTier Dockerfile until the first RUN line, where I then get the error hcsshim::CreateComputeSystem 186c82040b2e396b4b6e4c4063c2c8f562e855469630b82415e51043f6cb1773: An adapter was not found.

docker-compose.yml

version: '2.4'
services:
  webtier:
    image: webtier:win
    platform: windows
    ports:
      - 80
    build:
      context: .\WebTier
      dockerfile: Dockerfile
    depends_on:
      - apitier
    environment:
      ApiHost: "apitier"

  apitier:
    image: apitier:linux
    platform: linux
    expose: 
      - 80
    build:
      context: .\ApiTier
      dockerfile: Dockerfile

ApiTier\Dockerfile

FROM mcr.microsoft.com/dotnet/aspnet:2.1 AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/sdk:2.1 AS build
WORKDIR "/src/ApiTier"
COPY . .
RUN dotnet build "WebApi.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "WebApi.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "WebApi.dll"]

WebTier\Dockerfile

FROM mcr.microsoft.com/dotnet/framework/aspnet:4.7.2
WORKDIR /inetpub/wwwroot
COPY docker/ .

docker version

Client:
 Cloud integration: v1.0.29
 Version:           20.10.21
 API version:       1.41
 Go version:        go1.18.7
 Git commit:        baeda1f
 Built:             Tue Oct 25 18:08:16 2022
 OS/Arch:           windows/amd64
 Context:           default
 Experimental:      true

Server: Docker Desktop 4.15.0 (93002)
 Engine:
  Version:          20.10.21
  API version:      1.41 (minimum version 1.24)
  Go version:       go1.18.7
  Git commit:       3056208
  Built:            Tue Oct 25 18:03:04 2022
  OS/Arch:          windows/amd64
  Experimental:     true

docker-compose version

docker-compose version 1.29.2, build 5becea4c
docker-py version: 5.0.0
CPython version: 3.9.0
OpenSSL version: OpenSSL 1.1.1g  21 Apr 2020

Docker daemon json for Windows

{
  "experimental": true,
  "features": {
    "buildkit": false
  }
}

Docker daemon json for Linux

{
  "builder": {
    "gc": {
      "defaultKeepStorage": "20GB",
      "enabled": true
    }
  },
  "experimental": true,
  "features": {
    "buildkit": true
  }
}

Upvotes: 6

Views: 5453

Answers (1)

akathimi
akathimi

Reputation: 1571

Steps first, details later:

  1. Switch docker to use Windows containers
  2. In the Docker engine, set experimental to true (I see its already true on your end).
  3. select the "Use Docker Compose V2" in the docker settings (under General).
  4. run the docker-compose up -d command.

The example repo you have shared failed to build on my side, but I found a better example, and it works(with some mods of course :) )

sample docker-compose.yml:

version: '3.8'
services:
  nanoserver:
    container_name: nanoserver
    image: mcr.microsoft.com/windows/servercore/iis:windowsservercore-20H2
  sql2017:
    container_name: sql2017
    platform: linux
    mem_limit: 4GB
    environment:
      - ACCEPT_EULA=Y
      - MSSQL_PID=Developer
      - SA_PASSWORD=Mypass1.
    ports:
      - '1433:1433'
    image: mcr.microsoft.com/mssql/server:2017-latest

I am using the same docker versions (server and client) as you. However, I think v2 of docker-compose is needed:

$ docker-compose version
Docker Compose version v2.13.0

Make sure to select the "Use Docker Compose V2" in the docker settings. enter image description here

Refs:

Upvotes: 2

Related Questions