I am trying to run build plan on a windows docker container instead of directly on windows agent itself.
For some reason bamboo tries to start docker container with "--net host" mode and since windows container doesn't support this mode, it is failing. I need to find a way to prevent bamboo from using host mode, but I am not finding any configuration in my bamboo server.
Bamboo is trying to start container like following:
C:\Program Files\Docker\Docker\Resources\bin\docker.exe run --volume C:\Users\Administrator\bamboo-agent-home\xml-data\build-dir\PAN-PAND-JOB1:C:\Users\Administrator\bamboo-agent-home\xml-data\build-dir\PAN-PAND-JOB1 --volume C:\Users\Administrator\bamboo-agent-home\temp:C:\Users\Administrator\bamboo-agent-home\temp --detach --name 0eed3b21-3a3c-41e8-8e1b-1551be98f9c993388925 --net=host microsoft/windowsservercore tail -f /dev/null
... in: C:\Users\Administrator\bamboo-agent-home\xml-data\build-dir\PAN-PAND-JOB1
Following is the error I am receiving:
12-Apr-2019 15:53:06 Beginning to execute external process for build 'panda - panda-docker-WIP.py - Default Job #2 (PAN-PAND-JOB1-2)'\n ... running command line: \nC:\Program Files\Docker\Docker\Resources\bin\docker.exe run --volume C:\Users\Administrator\bamboo-agent-home\xml-data\build-dir\PAN-PAND-JOB1:C:\Users\Administrator\bamboo-agent-home\xml-data\build-dir\PAN-PAND-JOB1 --volume C:\Users\Administrator\bamboo-agent-home\temp:C:\Users\Administrator\bamboo-agent-home\temp --detach --name 0eed3b21-3a3c-41e8-8e1b-1551be98f9c993388925 --net=host microsoft/windowsservercore tail -f /dev/null\n ... in: C:\Users\Administrator\bamboo-agent-home\xml-data\build-dir\PAN-PAND-JOB1\n build 12-Apr-2019 15:53:07 8f45a0ceae2a7f29d1a7753ea54a1261e61551aa58c544184ff84edaa350342f error 12-Apr-2019 15:53:08 C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error response from daemon: network host not found. error 12-Apr-2019 15:53:08 Failed to start docker container 0eed3b21-3a3c-41e8-8e1b-1551be98f9c993388925 error 12-Apr-2019 15:53:08 com.atlassian.bamboo.docker.DockerException: Error running Docker run command error 12-Apr-2019 15:53:08 at com.atlassian.bamboo.docker.DockerContainerServiceImpl.run(DockerContainerServiceImpl.java:118) error 12-Apr-2019 15:53:08 at com.atlassian.bamboo.v2.build.agent.docker.DockerContainerControllerImpl.startContainerIfRequired(DockerContainerControllerImpl.java:79) error 12-Apr-2019 15:53:08 at com.atlassian.bamboo.v2.build.agent.DefaultBuildAgent.build(DefaultBuildAgent.java:173) error 12-Apr-2019 15:53:08 at com.atlassian.bamboo.v2.build.agent.BuildAgentControllerImpl.lambda$waitAndPerformBuild$0(BuildAgentControllerImpl.java:122) error 12-Apr-2019 15:53:08 at com.atlassian.bamboo.variable.CustomVariableContextImpl.withVariableSubstitutor(CustomVariableContextImpl.java:185) error 12-Apr-2019 15:53:08 at com.atlassian.bamboo.v2.build.agent.BuildAgentControllerImpl.waitAndPerformBuild(BuildAgentControllerImpl.java:117) error 12-Apr-2019 15:53:08 at com.atlassian.bamboo.v2.build.agent.DefaultBuildAgent$1.run(DefaultBuildAgent.java:126) error 12-Apr-2019 15:53:08 at com.atlassian.bamboo.utils.BambooRunnables$1.run(BambooRunnables.java:48) error 12-Apr-2019 15:53:08 at com.atlassian.bamboo.security.ImpersonationHelper.runWith(ImpersonationHelper.java:26) error 12-Apr-2019 15:53:08 at com.atlassian.bamboo.security.ImpersonationHelper.runWithSystemAuthority(ImpersonationHelper.java:17) error 12-Apr-2019 15:53:08 at com.atlassian.bamboo.security.ImpersonationHelper$1.run(ImpersonationHelper.java:41) error 12-Apr-2019 15:53:08 at java.lang.Thread.run(Unknown Source) error 12-Apr-2019 15:53:08 Caused by: com.atlassian.utils.process.ProcessException: Error executing C:\Program Files\Docker\Docker\Resources\bin\docker.exe run --volume C:\Users\Administrator\bamboo-agent-home\xml-data\build-dir\PAN-PAND-JOB1:C:\Users\Administrator\bamboo-agent-home\xml-data\build-dir\PAN-PAND-JOB1 --volume C:\Users\Administrator\bamboo-agent-home\temp:C:\Users\Administrator\bamboo-agent-home\temp --detach --name 0eed3b21-3a3c-41e8-8e1b-1551be98f9c993388925 --net=host microsoft/windowsservercore tail -f /dev/null error 12-Apr-2019 15:53:08 at com.atlassian.bamboo.docker.DockerContainerServiceImpl.execute(DockerContainerServiceImpl.java:255) error 12-Apr-2019 15:53:08 at com.atlassian.bamboo.docker.DockerContainerServiceImpl.run(DockerContainerServiceImpl.java:106) error 12-Apr-2019 15:53:08 ... 11 more
Script tasks to the rescue!
You CAN use docker on a Windows Agent, but it requires more manual steps.
I have docker running my builds on Windows 10 with:
There are various issues that I had to overcome, but now that everything is in place, it works very well.
That's not saying that Atlassian shouldn't support this feature natively (and it doesn't seem that difficult), but in case you want to implement docker containers in your build system, you can use the example YAML bamboo spec code below.
This code includes examples for:
You may also need to log into your repo, if required, but that's just another script task executing the docker login command.
Example Docker YAML Scripts:
Example Docker Tasks:
key: EDT
tasks:
## Pull the docker image
- script:
interpreter: BINSH_OR_CMDEXE
environment: DOCKER_HOST=${bamboo.docker_host}
scripts:
- docker pull ${bamboo.docker_image_name}
## Run the docker image as a new container with a couple of different volumes mounted
- script:
interpreter: BINSH_OR_CMDEXE
environment: DOCKER_HOST=${bamboo.docker_host}
scripts:
- docker run --volume ${bamboo.working.directory}:${bamboo.docker_container_build_dir} --volume c:\something_else:c:\something_else_in_container --detach --interactive --tty --net=nat --workdir=${bamboo.docker_container_build_dir} --name ${bamboo.docker_container_name} ${bamboo.docker_image_name}
## Execute a .NET build on the container
- script:
interpreter: BINSH_OR_CMDEXE
environment: DOCKER_HOST=${bamboo.docker_host}
scripts:
- docker exec -i -w ${bamboo.docker_container_build_dir} ${bamboo.docker_container_name} dotnet restore ${bamboo.solution_file}
## Stop the container because you can't use "docker cp" on a running Windows container
- script:
interpreter: BINSH_OR_CMDEXE
environment: DOCKER_HOST=${bamboo.docker_host}
scripts:
- docker stop ${bamboo.docker_container_name}
## Copy some files off of the container to the local file system
- script:
interpreter: BINSH_OR_CMDEXE
environment: DOCKER_HOST=${bamboo.docker_host}
scripts:
- docker cp ${bamboo.docker_container_name}:${bamboo.docker_container_buildoutput_dir} ${bamboo.working.directory}\buildoutput
## Remove the stopped container (container must be stopped first)
- script:
interpreter: BINSH_OR_CMDEXE
environment: DOCKER_HOST=${bamboo.docker_host}
scripts:
- docker rm ${bamboo.docker_container_name}
## Some variables
## This is necessary when using TCP for controlling the docker daemon.
## If you use named pipes, setting this environment variable is not required.
docker_host: tcp://localhost:2375
docker_registry: <address:port>
docker_registry_and_path: ${bamboo.docker_registry}/<your_path_on_registry>
docker_image_name: ${bamboo.docker_registry_and_path}/<your_image_name>:latest
docker_container_name: <some_identifier>-${bamboo.buildNumber}
docker_container_build_dir: c:\build
docker_container_buildoutput_dir: c:\buildoutput
solution_file: <your_solution_file>
Hi @Yogesh Gupta ,
Docker runner is not supported on Windows platform. Please, have a look at:
Kind regards,
Rafael
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.