Hiho,
I am trying to build and run a Docker-Container in a Jenkins pipeline and afterwards do some testing on the deyployed web-app in the container. Problem is my container only lives for some seconds and then dies with exit code 0. Already tried to run it in interactive mode and with and without the Docker Groovy Plugin.
My Pipeline Code looks like the following:
stage("Docker Build&Run") {
steps {
script {
def tag = "shop:${env.BUILD_ID}"
docker.build(tag)
//sh "docker run -d -p 8443:443/tcp ${tag}" Tried both
docker.image(tag).run('-p 8443:443/tcp')
}
}
}
stage("Dummy Dynamic Analysis") {
steps {
echo "Dummy Dynamic Analysis" //to be integrated
sleep 120 //application should be available here since it has to be theire for testing as well
}
}
Events look like these. Destroyed after some seconds:
2018-11-07T17:27:30.104407703+01:00 image tag sha256:21ae4ef9603d390d0244cee30651485f2fb517a47c9e9d2c38855d093349105c (name=shop:35)
2018-11-07T17:27:31.260144894+01:00 container create ade7069d9d391146611f4f658156554823cc8086bd6769bbc32c3949d5b1a694 (image=shop:35, name=suspicious_liskov)
2018-11-07T17:27:31.456730373+01:00 network connect 36c2d6617773a7c7075caece71bcd744c89009b3db1962328d0f9930d981238a (container=ade7069d9d391146611f4f658156554823cc8086bd6769bbc32c3949d5b1a694, name=bridge, type=bridge)
2018-11-07T17:27:31.966564913+01:00 container start ade7069d9d391146611f4f658156554823cc8086bd6769bbc32c3949d5b1a694 (image=shop:35, name=suspicious_liskov)
2018-11-07T17:27:35.761690515+01:00 container die ade7069d9d391146611f4f658156554823cc8086bd6769bbc32c3949d5b1a694 (exitCode=0, image=shop:35, name=suspicious_liskov)
2018-11-07T17:27:35.929597196+01:00 network disconnect 36c2d6617773a7c7075caece71bcd744c89009b3db1962328d0f9930d981238a (container=ade7069d9d391146611f4f658156554823cc8086bd6769bbc32c3949d5b1a694, name=bridge, type=bridge)
How can I deploy the container and let it running for either unlimited time until stopped or atleast for the whole time jenkins is running?
Thanks in advance to everybody. Greetings