I'm looking for a way to run Docker-enabled build consisting of multiple containers in Jenkins 2.0.
Are there any plans for native support of Docker Compose in Pipeline, or through CloudBees docker plugins for pipeline.
Or can/must this be addressed by explicit calls sh docker-compose...
? Maybe even use them inside try... finally
to further control services lifecycle.
EDIT: The first answer was to suggest a way to build docker containers in jenkins. This is not what is needed here. I (EngineerDollery) want to bring up my target platform in jenkins using compose so that I can deploy my app to it and run end-to-end tests.
After searching in Jenkins bug tracking, JENKINS-35025 suggests docker-compose.yml
is taken into account when running a job in a docker container, using a maven build.
See also Creating CI pipeline with Jenkins, which assumes docker-compose is installed on your Jenkins server.
Note: a year later (August 2017), docker-compose is still not supported in the Docker Pipeline plugin
July 2018, Ivan Aracki notes in the comments:
Manually installing docker-cli
and docker-compose
with the same version as host's is the solution for now...
Here are the files to run a jenkins container that runs docker inside:
docker run \
-p 8080:8080 \
-v /var/run/docker.sock:/var/run/docker.sock \
--name jenkins \
getintodevops/jenkins-withdocker:lts
reference: https://getintodevops.com/blog/the-simple-way-to-run-docker-in-docker-for-ci
I am facing a similar problem, I found this https://reinout.vanrees.org/weblog/2017/10/03/docker-compose-in-jenkins.html but I do not know what is related to.
My problem is test while developing, and also automate the test in Jenkins, and I am using docker-compose to bring up some php scripts AND a mysql server, to run isolated tests (phpunit as of now).
I could think I can achieve this by
- creating a network in docker host (with
docker network create
)
- create and run a mysql docker attached to that network (with
docker run mysql --network=netname --name=mysqlmachine
- run scripts by jenkins specifying --network and refering to
mysqlmachine
as host.
But this would means I need to setup db data, cleanup db data, and also leave always on the mysqlmachine even when not needed, consuming some ram resource. I can solve last problem with docker start mysqlmachine
and docker stop mysqlmachine
command in my Jenkinsfile defining the pipeline.
But, again, executing a shell into the docker where jenkins is running I can not find docker
command
For me is a viable solution untill I can not find something better
UPDATE:
I will try the https://wiki.jenkins.io/display/JENKINS/Docker+Slaves+Plugin solution, it has almost what I need
UPDATE 08.02:
as suggest by Alexander Zeitler, using
agent {
docker {
image 'pdmlab/jenkins-node-docker-agent:6.11.1'
args '-v /var/run/docker.sock:/var/run/docker.sock'
}
}
in Jenkins file allow the use of docker-compose command: docker inside a docker, that is mostly docker near a docker as detailed here: Docker in Docker - volumes not working: Full of files in 1st level container, empty in 2nd tier
But I preferred to use another approach, that does not require to run jenkins in a special way.
The pipeline say:
stage('Test') {
steps {
sh './build_docker.sh jenkinstests'
}
}
and build_docker.sh does:
jenkinstests)
docker volume create idealodbconn
docker run -v idealodbconn:/data --name helper busybox true
docker cp ./dbconn/db249.json helper:/data
docker rm helper
docker-compose -f services/docker-compose-jenkins.yml up \
--abort-on-container-exit \
--exit-code-from idealoifapi
docker-compose -f services/docker-compose-jenkins.yml rm -f
docker volume rm idealodbconn
;;
Also here --abort-on-container-exit
say to exit once one container defined into docker-compose-jenkins.yml exits, and --exit-code-from idealoifapi
says to take exit code from idealoifapi image.
That is all. Missing part, maybe, is the docker-compose-jenkins.yml use of volume, it is external: true:
volumes:
idealodbconn:
external: true