microsoft / azure-pipelines-tasks

Tasks for Azure Pipelines
https://aka.ms/tfbuild
MIT License
3.45k stars 2.6k forks source link

Running docker on Windows-2022 agent with linux image #16089

Open johnsimons opened 2 years ago

johnsimons commented 2 years ago

Required Information

Type: Question

Enter Task Name: CmdLine

Environment

Issue Description

Is it possible to run Linux based images in windows-2022 agents? I don't seem to be able.

Here is an example of what I am trying to do:

trigger: none
name: 1.0.$(Build.BuildId)
variables:
  sa_password: 'yourStrong45@Password'
resources:
  containers:
  - container: sqlserver
    image: mcr.microsoft.com/mssql/server:2019-latest
    env:
      ACCEPT_EULA: Y
      SA_PASSWORD: ${{ variables.sa_password }}
      MSSQL_PID: Developer
    options: >-
      --health-cmd "/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P \"${{ variables.sa_password }}\" -Q \"SELECT 1\" || exit 1"
      --health-interval 10s
      --health-timeout 3s
      --health-retries 10
      --health-start-period 10s
    - 1433:1433

jobs:
- job: my-job
  timeoutInMinutes: 5
  cancelTimeoutInMinutes: 2
  services:
    sqlserver: sqlserver
  displayName: Version 5+
  strategy:
    matrix:
      windows:
        image: windows-latest
        os: win
        cliVersion: '8.*'
        sqlserver: sqlserver-win
      linux:
        image: ubuntu-latest
        os: linux
        cliVersion: '*'
        sqlserver: sqlserver
  pool:
    vmImage: $(image)
  steps:
  - checkout: self
    fetchDepth: 1
  - task: NodeTool@0
    inputs:
      versionSpec: '16.x'
    ## The following task need sqlserver instance
  - task: CmdLine@2
    displayName: Run setup
    env:
      OCTOPUS_SERVER: $(server_url)
      OCTOPUS_API_KEY: $(admin_api_key)
    inputs:
      script: |
        cd .azure
        npm install
        npx ts-node index.ts

As we know mcr.microsoft.com/mssql/server:2019-latest is only available on linux.

Error logs

2022-03-30T04:04:15.8420750Z ##[debug]Evaluating condition for step: 'Initialize containers'
2022-03-30T04:04:15.8471644Z ##[debug]Evaluating: SucceededNode()
2022-03-30T04:04:15.8480214Z ##[debug]Evaluating SucceededNode:
2022-03-30T04:04:15.8556963Z ##[debug]=> True
2022-03-30T04:04:15.8570947Z ##[debug]Result: True
2022-03-30T04:04:15.8636910Z ##[section]Starting: Initialize containers
2022-03-30T04:04:16.5193145Z ##[debug]Current Windows version: '1809 (Server)'
2022-03-30T04:04:16.5234527Z ##[command]C:\Program Files\Docker\docker.EXE version --format '{{.Server.APIVersion}}'
2022-03-30T04:04:22.4574981Z '1.41'
2022-03-30T04:04:22.4637442Z Docker daemon API version: '1.41'
2022-03-30T04:04:22.4638009Z ##[command]C:\Program Files\Docker\docker.EXE version --format '{{.Client.APIVersion}}'
2022-03-30T04:04:22.7039997Z '1.41'
2022-03-30T04:04:22.7101189Z Docker client API version: '1.41'
2022-03-30T04:04:22.7120176Z ##[debug]Delete stale containers from previous jobs
2022-03-30T04:04:22.7129844Z ##[command]C:\Program Files\Docker\docker.EXE ps --all --quiet --no-trunc --filter "label=635439"
2022-03-30T04:04:23.0646449Z ##[debug]Delete stale container networks from previous jobs
2022-03-30T04:04:23.0688185Z ##[command]C:\Program Files\Docker\docker.EXE network prune --force --filter "label=635439"
2022-03-30T04:04:23.4288653Z ##[command]C:\Program Files\Docker\docker.EXE pull mcr.microsoft.com/mssql/server:2019-latest
2022-03-30T04:04:24.9983765Z 2019-latest: Pulling from mssql/server
2022-03-30T04:04:25.1287785Z image operating system "linux" cannot be used on this platform
2022-03-30T04:04:25.1371081Z ##[warning]Docker pull failed with exit code 1, back off 6.75 seconds before retry.
2022-03-30T04:04:31.8890119Z ##[command]C:\Program Files\Docker\docker.EXE pull mcr.microsoft.com/mssql/server:2019-latest
2022-03-30T04:04:32.2948369Z 2019-latest: Pulling from mssql/server
2022-03-30T04:04:32.4342813Z image operating system "linux" cannot be used on this platform
2022-03-30T04:04:32.4406681Z ##[warning]Docker pull failed with exit code 1, back off 1.593 seconds before retry.
2022-03-30T04:04:34.0460106Z ##[command]C:\Program Files\Docker\docker.EXE pull mcr.microsoft.com/mssql/server:2019-latest
2022-03-30T04:04:34.6016908Z 2019-latest: Pulling from mssql/server
2022-03-30T04:04:34.7511315Z image operating system "linux" cannot be used on this platform
2022-03-30T04:04:34.7885777Z ##[error]Docker pull failed with exit code 1
2022-03-30T04:04:34.7891064Z ##[debug]System.InvalidOperationException: Docker pull failed with exit code 1
   at Microsoft.VisualStudio.Services.Agent.Worker.ContainerOperationProvider.PullContainerAsync(IExecutionContext executionContext, ContainerInfo container)
   at Microsoft.VisualStudio.Services.Agent.Worker.ContainerOperationProvider.PullContainerAsync(IExecutionContext executionContext, ContainerInfo container)
   at Microsoft.VisualStudio.Services.Agent.Worker.ContainerOperationProvider.StartContainersAsync(IExecutionContext executionContext, Object data)
   at Microsoft.VisualStudio.Services.Agent.Worker.JobExtensionRunner.RunAsync()
   at Microsoft.VisualStudio.Services.Agent.Worker.StepsRunner.RunStepAsync(IStep step, CancellationToken jobCancellationToken)
2022-03-30T04:04:34.7899643Z ##[section]Finishing: Initialize containers
KonstantinTyukalov commented 2 years ago

Hi @johnsimons! Could you please describe your use case in more detail? Are you trying to use the Linux docker image inside the pipeline that targets windows-2022 image? Also, would you mind sharing the YAML schema of your pipeline?

johnsimons commented 2 years ago

Hi @KonstantinTyukalov, thanks for getting back to me, yes that is exactly what I am attempting to do. I have updated the main description and provided a sample yaml pipeline.

mmulhearn commented 2 years ago

I am also running into this issue. I have a task in my pipeline that requires Windows so my agent is on a Windows image. I need the Static Web App task to allow linux docker images on Windows agents.

2022-04-20T13:50:43.8890228Z [command]"C:\Program Files\Git\bin\bash.exe" D:\a\_tasks\AzureStaticWebApp_18aad896-e191-4720-88d6-8ced4806941a\0.200.0\launch-docker.sh
2022-04-20T13:50:50.0871030Z stable: Pulling from appsvc/staticappsclient
2022-04-20T13:50:50.1942192Z docker: image operating system "linux" cannot be used on this platform.
2022-04-20T13:50:50.1943444Z See 'docker run --help'.
2022-04-20T13:50:50.2111535Z ##[error]Error: The process 'C:\Program Files\Git\bin\bash.exe' failed with exit code 125
stefanhendriks commented 2 years ago

Same here:

- task: AzureStaticWebApp@0
  inputs:
    app_location: '<snip>/dist'
    api_location: ''
    output_location: ''
  env:
    azure_static_web_apps_api_token: $(DeploymentToken)

Results into:

Starting: AzureStaticWebApp
==============================================================================
Task         : Deploy Azure Static Web App
Description  : [PREVIEW] Build and deploy an Azure Static Web App
Version      : 0.200.0
Author       : Microsoft Corporation
Help         : https://aka.ms/swadocs
==============================================================================
"C:\Program Files\Git\bin\bash.exe" D:\a\_tasks\AzureStaticWebApp_18aad896-e191-4720-88d6-8ced4806941a\0.200.0\launch-docker.sh
stable: Pulling from appsvc/staticappsclient
docker: image operating system "linux" cannot be used on this platform.
See 'docker run --help'.
##[error]Error: The process 'C:\Program Files\Git\bin\bash.exe' failed with exit code 125
Finishing: AzureStaticWebApp

Running on:

pool:
  vmImage: 'windows-2019'

(I cannot use windows-latest in my case, but it must be a windows image)

stefanhendriks commented 2 years ago

I worked around this issue by executing this task in a separate job with a linux image. However, preferred way would be to be able to run this within one and the same vm image. So basically I grouped all my windows related tasks in a "Windows" job, and this specific task in a "Linux" job. (in my case, Windows jobs are "backend" and "Linux" equals to "Frontend", but alas)

aaggarwal28 commented 2 years ago

I worked around this issue by executing this task in a separate job with a linux image. However, preferred way would be to be able to run this within one and the same vm image. So basically I grouped all my windows related tasks in a "Windows" job, and this specific task in a "Linux" job. (in my case, Windows jobs are "backend" and "Linux" equals to "Frontend", but alas)

Suppose Created DB Container in Job1 (ubuntu-linux) and application ran in job 2 (windows), how will connect the job1(Linux) Container DB from job2 (Windows) Test Application?

could you please guide ?

pschoffer commented 2 years ago

I am running into the same issue I think. I opened a discussion in github forum in case it would get some traction there.

tmeckel commented 1 year ago

If you look at the script to install Docker CE on a Windows Agent:

https://github.com/actions/runner-images/blob/main/images/win/scripts/Installers/Install-Docker.ps1

You'll notice that on execution the parameter -HyperV is not passed. Thus Docker CE isn't able to run Linux containers because this would require Hyper-V support, because on a Windows Host, Linux Containers must run inside a VM. Eventually this would require nested VM support enabled for the VM running the Windows Agent. I doubt Microsoft configured the VMs for GitHub or Azure DevOps, which host/run the pipeline agents, that way.

xecollons commented 1 year ago

I encountered this and it's very frustrating. I'm trying to create some integration tests against a SQL Server contained database from a windows image (since our compilation has to be done in windows for reasons) and I can't since it can run linux containers.

And what is even more absurd is that Microsoft doesn't even provide any Windows SQL Server image that can be pulled from docker hub.

Anyone would tell that Windows is MS primary OS.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 180 days with no activity. Remove the stale label or comment on the issue otherwise this will be closed in 5 days

Emilgardis commented 1 year ago

Could we maybe add backlog to this? It's still very much an issue

github-actions[bot] commented 9 months ago

This issue is stale because it has been open for 180 days with no activity. Remove the stale label or comment on the issue otherwise this will be closed in 5 days

Emilgardis commented 9 months ago

still an issue

ryangurn commented 9 months ago

I encountered this and it's very frustrating. I'm trying to create some integration tests against a SQL Server contained database from a windows image (since our compilation has to be done in windows for reasons) and I can't since it can run linux containers.

And what is even more absurd is that Microsoft doesn't even provide any Windows SQL Server image that can be pulled from docker hub.

Anyone would tell that Windows is MS primary OS.

This is my exact issue at this point. I am attempting to get a windows server container started along side a mssql container. I am just using this as a development environment, so ill install mssql locally and expose the ports between my host and the container.

asarra commented 5 months ago

Still an issue

joshbybee commented 1 month ago

This is still irritating,

I'm trying to use the new Testcontainers library to containerize my SQL Server testing on my AzureDevOps pipelines--- but it doesn't work without creating a secondary job using ubunut-latest with duplicate tasks if you want your actual build that is promoted to be on windows-latest.