0
0
Jenkinsdevops~10 mins

Docker compose in pipelines in Jenkins - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Docker compose in pipelines
Start Jenkins Pipeline
Checkout Code
Run 'docker-compose up'
Services Start
Run Tests or Build Steps
Run 'docker-compose down'
Cleanup and Finish Pipeline
This flow shows how a Jenkins pipeline uses docker-compose to start services, run tests, then clean up.
Execution Sample
Jenkins
pipeline {
  agent any
  stages {
    stage('Start Services') {
      steps { sh 'docker-compose up -d' }
    }
    stage('Test') {
      steps { sh './run-tests.sh' }
    }
    stage('Cleanup') {
      steps { sh 'docker-compose down' }
    }
  }
}
A Jenkins pipeline that starts services with docker-compose, runs tests, then stops services.
Process Table
StepActionCommand RunResultPipeline State
1Checkout Codegit clone repoCode readyReady to start services
2Start Servicesdocker-compose up -dContainers startedServices running
3Run Testsrun-tests.shTests passedTesting
4Cleanupdocker-compose downContainers stoppedServices stopped
5Pipeline EndN/APipeline successFinished
💡 Pipeline ends after cleanup stage stops all docker-compose services.
Status Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
CodeNot checked outChecked outChecked outChecked outChecked out
ServicesStoppedRunningRunningStoppedStopped
TestsNot runNot runPassedPassedPassed
Pipeline StateIdleRunning servicesTestingServices stoppedFinished
Key Moments - 3 Insights
Why do we run 'docker-compose up' before tests?
Because the tests need the services running to connect to them. See execution_table step 2 and 3 where services start before tests run.
What happens if we skip 'docker-compose down'?
Containers keep running and may cause conflicts later. The cleanup step (step 4) stops containers to keep the environment clean.
Why use '-d' flag with 'docker-compose up'?
The '-d' runs containers in the background so the pipeline can continue to the next steps without waiting.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the pipeline state after step 3?
AServices running
BCleaning up
CTesting
DFinished
💡 Hint
Check the 'Pipeline State' column in execution_table row for step 3.
At which step are the docker containers stopped?
AStep 4
BStep 3
CStep 2
DStep 5
💡 Hint
Look for 'Containers stopped' in the 'Result' column of execution_table.
If we remove '-d' from 'docker-compose up', what changes in the pipeline?
AContainers start in background as usual
BPipeline waits until containers stop before next step
CTests run before containers start
DPipeline fails immediately
💡 Hint
Recall that '-d' runs containers detached; without it, the command blocks.
Concept Snapshot
Jenkins pipeline with docker-compose:
- Use 'docker-compose up -d' to start services in background
- Run tests after services are ready
- Use 'docker-compose down' to stop and clean containers
- Keeps pipeline clean and services isolated
- Order matters: start -> test -> cleanup
Full Transcript
This visual execution shows how a Jenkins pipeline uses docker-compose commands step-by-step. First, the pipeline checks out the code. Then it runs 'docker-compose up -d' to start services in the background. After services are running, tests execute. Finally, 'docker-compose down' stops the containers to clean up. Variables like services state and pipeline state update at each step. Key points include why '-d' is used to run containers detached and why cleanup is important to avoid leftover containers. The quiz questions check understanding of pipeline states and command effects.