Reputation: 135
I am trying to build deploy my code using jenkins pipeline and also using remote docker daemon for deployment. everything is working but jenkins pipeline is stoping and removing all containers once pipeline script ends. server is coming up just for 10 seconds after that container stops and removed.
stage {
steps {
script {
docker.withServer('tcp://10.10.10.10:2375') {
docker.withRegistry('https://registry.my.com/','jenkins-registry') {
docker.image('registry.my.com/image-my/my:latest').withRun(' -p 9090:80 -i -t --name harpal ') {
sh 'docker ps -a'
}
}
}
}
}
output
[Flights-Docker-POC] Running shell script
+ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6a4c5094a8d2 registry.my.com/image-my/my:latest "/usr/bin/supervisord" 6 hours ago Up Less than a second 0.0.0.0:9090->80/tcp harpal
[Pipeline] sh
[Flights-Docker-POC] Running shell script
+ docker stop 6a4c5094a8d22179b364ee2d3b97e998a2c13e8b136c55816c0d8f838c17248b
6a4c5094a8d22179b364ee2d3b97e998a2c13e8b136c55816c0d8f838c17248b
+ docker rm -f 6a4c5094a8d22179b364ee2d3b97e998a2c13e8b136c55816c0d8f838c17248b
6a4c5094a8d22179b364ee2d3b97e998a2c13e8b136c55816c0d8f838c17248b
Upvotes: 0
Views: 3346
Reputation: 135
got the answer for it.it wasn't issue related to entry point in my image
was suppose to use image.run() method instead of withRun(), withRun() method internally calls run() method and stops container in finally block of its implementation.
public <V> V withRun(String args = '', Closure<V> body) {
docker.node {
Container c = run(args)
try {
body.call(c)
} finally {
c.stop()
}
}
}
btw thank you guys for help.
script was supposed to be like.
stage {
steps {
script {
docker.withServer('tcp://10.10.10.10:2375') {
docker.withRegistry('https://registry.my.com/','jenkins-registry') {
docker.image('registry.my.com/image-my/my:latest').run(' -p 9090:80 -i -t --name harpal ')
}
}
}
}
Upvotes: 1
Reputation:
I don't believe there is a way to keep it alive using that Docker plugin Groovy class, it's intended to remove the container after the run.
If you're just trying to launch Docker containers from Jenkins, just use shell commands to do a
sh 'docker run -p 9090:80 -i -t --name harpal registry.my.com/image-my/my:latest '
If you're trying to keep a container alive to debug it and look around I usually add
sh 'sleep 30m'
Then go to the Docker machine and take a look around the container with
docker exec -it <ContainerID> bash
Upvotes: 0