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:
- Bamboo Server 7.2.3
- Docker Desktop 4.2.0
- Using Bamboo-Specs
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
- Pulling your docker image
- Running your image as a container
- Executing commands on your container
- Stopping the container
- Copying files off of the container to the host system
- Removing the container
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:
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>
7 years later and this is still an issue? Come on Atlassian, you're wondering why companys move away from Bamboo and your products?