docker getting stopped, how to launch a background process

12 views
Skip to first unread message

Eser Kandogan

unread,
Sep 24, 2019, 6:05:23 PM9/24/19
to Jenkins Users
Hi,

As part of my jenkins pipeline I would like to launch a server in a docker image but it seems docker is stopped when/if the last command is put in background. How can I fix this? Here is the Jenkinsfile:

node {
    checkout scm
    def backendImage = docker.build("backend-image", "./images/backend")

    sh 'export JENKINS_NODE_COOKIE=dontKillMe'

    backendImage.inside('-p 3000:3000 -p 4000:4000') {

          echo "BUILDING BACKEND"
          echo "----------------"
          echo "STEP1: INSTALLING REQUIREMENTS..."
          sh 'pip install -r requirements.txt'

          echo "STEP2: TESTING..."
          sh 'python test.py'

          echo "STEP3: START PRODUCTION SERVER"

          sh 'export JENKINS_NODE_COOKIE=dontKillMe'
          sh 'nohup python app.py -p 3000 >> app.prod.log &'

    }

}

In above if I remove the & in nohup call the pipeline never finishes but the process runs. If I add an & at the end the docker is stopped and removed. I see the following in command output:
+ nohup python app.py -p 3000
[Pipeline] }
$ docker stop --time=1 e33a650bab7c565148899e28f229a0ec19577b1701227cc89b52752b851a34be
$ docker rm -f e33a650bab7c565148899e28f229a0ec19577b1701227cc89b52752b851a34be


Dockerfile in images/backend is:

FROM python:3.7


MAINTAINER Eser Kandogan "..."


RUN apt-get update -y && \

    apt-get install -y python-pip python-dev

Reply all
Reply to author
Forward
0 new messages