Created
November 27, 2019 05:38
-
-
Save shaunthegeek/30288ca2252f9463b79c30306fedc649 to your computer and use it in GitHub Desktop.
Jenkins multiple Docker containers in the background, instead of sidecar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| node { | |
| checkout scm | |
| sh 'docker network create bridge1'; | |
| sh(script:'docker run --net bridge1 --name mysql -d -e "MYSQL_ROOT_PASSWORD=my-secret-pw" -e "MYSQL_DATABASE=test" mysql:5.7', returnStdout: true) | |
| sh(script:'docker run --net bridge1 --name redis -d redis:5', returnStdout: true) | |
| def testImage = docker.build("test-image:${env.BUILD_ID}", "-f Dockerfile ./") | |
| testImage.inside('--net bridge1 -e "DB_HOST=mysql" -e "REDIS_HOST=redis" -e "DB_DATABASE=test" -e "DB_USERNAME=root" -e "DB_PASSWORD=my-secret-pw"') { | |
| stage('Prepare') { | |
| echo 'preparing' | |
| sh 'env' | |
| sh 'apt-get update && apt-get install -y librsvg2-bin' | |
| } | |
| stage('Test') { | |
| echo 'testing...' | |
| sh 'ls' | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When do these started dockers stop? at the end of pipeline, at the end of the step? Do I have to stop them manually?