Gitlab does not provide runner's helper image for Windows server 2022
Summary
Gitlab runner fails the job and forwards message from docker engine: The container operating system does not match the host operating system. (exec.go:67:0s)
Running manually (docker run --rm -it mcr.microsoft.com/windows/servercore:ltsc2022-amd64 powershell
) works just fine.
Steps to reproduce
-
Order AWS EC2 instance (e.g.
t3.medium
) with "Microsoft Windows Server 2022 Base -ami-0cf27351cfa5f53d7
". Docker enterprise is installed by default and this AMI has container support out of the box. Docker by default usesprocess
isolation mode, therefore hyper-v support is not needed. -
Double check if docker works (it indeed works):
docker run --rm -it mcr.microsoft.com/windows/servercore:ltsc2022-amd64 powershell
To tripple check if it works, run the image that should not work and indeed it does not work:
docker run --rm -it mcr.microsoft.com/windows/servercore:20H2-amd64 powershell
docker: Error response from daemon: hcsshim::CreateComputeSystem c919e8ba8ef4f19e7af5c6a2d32430362f41679197db89cd793d6d3a987125b5: The container operating system does not match the host operating system.
- Install Gitlab-Runner, register runner to (company's) Gitlab. Here is the configuration file I am using (
C:\Gitlab-Runner\config.toml
):
concurrent = 1
check_interval = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "Example Gitlab runner"
url = "https://example.com/"
token = "XXXXXXXXXXXXXXXXXXXX"
executor = "docker-windows"
shell = "pwsh"
[runners.custom_build_dir]
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
[runners.cache.azure]
[runners.docker]
tls_verify = false
image = "mcr.microsoft.com/windows/servercore:ltsc2022-amd64"
privileged = false
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["c:\\cache"]
shm_size = 0
- Run below CI (.gitlab-ci.yml) job:
default:
tags:
- test-windows-runner
build-job:
stage: build
script:
- echo "Hello world!"
- sleep 5
- Get the error:
Running with gitlab-runner 14.5.1 (de104fcd)
on Example Gitlab runner XXXXXXXX
Preparing the "docker-windows" executor 00:00
Using Docker executor with image mcr.microsoft.com/windows/servercore:ltsc2022-amd64 ...
Pulling docker image mcr.microsoft.com/windows/servercore:ltsc2022-amd64 ...
Using docker image sha256:3d4792f88e26c7214b15465629517be53ffb46b5cfd1179e70132171777635c6 for mcr.microsoft.com/windows/servercore:ltsc2022-amd64 with digest mcr.microsoft.com/windows/servercore@sha256:1a70f9c7e5eb294ced470d7646c9c81f90fe9b709c4212445820678f967ae543 ...
Preparing environment 00:01
ERROR: Job failed (system failure): prepare environment: Error response from daemon: hcsshim::CreateComputeSystem c0494740db046e578a4bfd310340f6acd341ec667d97320d756b53798fe7b0c4: The container operating system does not match the host operating system. (exec.go:67:0s). Check https://docs.gitlab.com/runner/shells/index.html#shell-profile-loading for more information
Workaround:
The main "issue" is that you can only run the same Windows verions inside the containers, matching host versions. In my case, I've used the same Windows version for the container, but Gitlab pulled it's own helper image that did not match host Windows version.
As a workaround, one could use earlier version of Windows. Check this link in order to find out what Windows versions are supported: https://registry.hub.docker.com/r/gitlab/gitlab-runner-helper/tags?name=servercore
Bonus: You can specify your custom helper image in Gitlab runner's configuration file: https://stackoverflow.com/a/67627589