Windows 环境中的测试容器在 GitHub 操作:"Could not find a valid Docker environment. Please see logs and check configuration"

Testcontainers in Windows environment on GitHub Actions: "Could not find a valid Docker environment. Please see logs and check configuration"

我们正在使用 testcontainers-java heavily in our spring-boot-admin project. Since we also want to be able to run our Maven build also on Windows, we added a windows-latest environment to our GitHub Actions Pipeline using a Matrix strategy build () 像这样:

name: build

on:
  push:

jobs:
  build:
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest]

    runs-on: ${{ matrix.os }}
    steps:

      - uses: actions/checkout@v2

      - name: Set up JDK 1.8
        uses: actions/setup-java@v1
        with:
          java-version: 1.8

      - name: Build with Maven
        run: |
          mvn -B install --no-transfer-progress

现在我们的 Testcontainers JUnit 测试用例失败了(参见 full build log):

[INFO] Running de.codecentric.boot.admin.server.eventstore.HazelcastEventStoreWithClientConfigTest
Error:  Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.877 s <<< FAILURE! - in de.codecentric.boot.admin.server.eventstore.HazelcastEventStoreWithClientConfigTest
Error:  de.codecentric.boot.admin.server.eventstore.HazelcastEventStoreWithClientConfigTest  Time elapsed: 0.877 s  <<< ERROR!
java.lang.IllegalStateException: Could not find a valid Docker environment. Please see logs and check configuration

那么知道我们可以做些什么来解决这个问题吗?

问题是在 Windows 服务器中默认只有 Windows 个容器激活(没有 Linux 个容器)。 As Sergei Egorov stated:

The problem with windows-latest is that it uses Windows containers, not Linux containers. It means that Testcontainers itself works, but all the images that it starts are Linux-based and, in Windows containers mode, they obviously fail to start :)

对此的“修复”是启用 GitHub 操作环境并启用 Linux 容器!但是经过一些谷歌搜索之后,这似乎并不那么容易。首先,我认为 LCOW(Windows 上的 Linux 容器)只需要启用。但正如 this great elaboration 所述,在 GitHub 操作 Windows 环境中激活 LCOW 并不容易(甚至不可能)。

我深入研究了这个问题,发现 that LCOW was officially deprecated in 20.10 in favour of WSL2, that brings in native Linux runtime and also Docker for Desktop on Windows 10 already favours this approach

但是:我们在 Windows Server 2019 上,而不是 Windows 10 桌面。在 GitHub 操作上,我们只有 nano 风格的服务器版本。很遗憾 an open issue for the WSL2 support in Windows Server 2019. And scanning the GitHub Actions Windows Server 2019 docs 我发现现在只安装了 WSLv1。