Reputation: 11962
I am trying to build windows container using https://gitlab.com, but I didnot find if this is supported or not.
I made a test with a really simple Dockerfile:
FROM mcr.microsoft.com/windows/servercore:ltsc2019
CMD echo "Hello World from Windows"
Using .gitlab-ci.yml
image: docker
services:
- docker:dind
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
windows:
stage: build
script:
- docker build -t ${CI_REGISTRY}/${CI_PROJECT_PATH}:${CI_COMMIT_REF_SLUG} .
- docker push ${CI_REGISTRY}/${CI_PROJECT_PATH}:${CI_COMMIT_REF_SLUG}
It fails with :
image operating system "windows" cannot be used on this platform
ERROR: Job failed: exit code 1
Looking for the documentation of gitlab-runner, it seems supported https://docs.gitlab.com/runner/executors/#selecting-the-executor.
Is there a way to build a windows container from the online service ?
Upvotes: 7
Views: 9629
Reputation: 21
@mpromonet solution no longer works without adding an extra line to start the docker service because now is not starting by default like before.
Add a before_script
section with - Start-Service -Name "docker"
Updated example:
windows:
stage: build
tags:
- shared-windows
- windows
- windows-1809
before_script:
- Start-Service -Name "docker"
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build -t ${CI_REGISTRY}/${CI_PROJECT_PATH}:${CI_COMMIT_REF_SLUG} .
- docker push ${CI_REGISTRY}/${CI_PROJECT_PATH}:${CI_COMMIT_REF_SLUG}
Source: https://forum.gitlab.com/t/docker-daemon-not-running-on-windows-shared-runner/83245
Upvotes: 1
Reputation: 11962
Since January 2020 it is possible to build a windows container using online service using the Windows Shared Runners (beta).
Today, we are happy to announce that Windows Shared Runners hosted by GitLab is available in beta. As we are starting to roll out this important service to our community, we invite you to help shape the direction of CI/CD tooling for the Windows ecosystem on GitLab.com
For instance, using the following .gitlab-ci.yml
windows:
stage: build
tags:
- shared-windows
- windows
- windows-1809
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build -t ${CI_REGISTRY}/${CI_PROJECT_PATH}:${CI_COMMIT_REF_SLUG} .
- docker push ${CI_REGISTRY}/${CI_PROJECT_PATH}:${CI_COMMIT_REF_SLUG}
With a simple Dockerfile
FROM mcr.microsoft.com/windows/servercore:ltsc2019
CMD echo "Hello World from Windows"
The pipeline execution result
Upvotes: 7
Reputation: 1328192
This should be supported with GitLab 1.11 (May 2019)
Windows Container Executor for GitLab Runner
In GitLab 11.11 we are pleased to add a new executor to the GitLab Runner for using Docker containers on Windows.
Previously, using the shell executor to orchestrate Docker commands was the primary approach for Windows, but with this update you are now able to use Docker containers on Windows directly, in much the same way as if they were on Linux hosts.
This opens up the door for more advanced kinds of pipeline orchestration and management for our users of Microsoft platforms.Included with this update is improved support for PowerShell throughout GitLab CI/CD, as well as new helper images for various versions of Windows containers.
Please note that your own Windows runners can be used with GitLab.com, but are not currently available as part of the shared public fleet.
This is from issue 535: see the documentation "Using Windows containers".
It has limitations, but it is a good first step.
Upvotes: 2
Reputation: 5644
As far as I know, the runners provided by GitLab.com are all Linux based. You'll need to provide your own runner with a Windows-based Docker engine to build a Windows Docker image.
Upvotes: 2