Reputation: 335
I have a question about deploy image docker using declarative pipelines.
I have the following script in Jenkins.
pipeline {
agent any
stages {
stage('Clean Package') {
steps {
sh 'mvn clean package -DskipTests'
}
}
stage('Build Docker') {
steps {
sh 'docker build -t servicio-eureka-server:v1 .'
}
}
}
}
The image is built correctly but I suppose that I need to use a Kubernetes cluster to run an image docker.
Because I try to add another stage call docker run and when I use this command the pipeline is always running.
Could anyone help me?
Upvotes: 0
Views: 43
Reputation: 46
The image is build correctly but I supose that I need to use a kbernetes cluster to run an image docker.
Because I try to add another stage call docker run and when I use this command the pipeline is always running.
Based on your messages it's not 100% clear what you're doing / trying to do but it sounds like maybe you're adding another stage that does docker run <args>
which starts up a docker container but the pipeline never terminates because that command continues to run forever? If you use docker run -d <args>
it will run the container as a daemon, which will allow your pipeline to terminate.
That being said, I would not recommend running / deploying your offering's docker containers directly onto your Jenkins worker node, especially if you are using the Jenkins docker plugin to dynamically provision build agents. Most likely the best thing you can do is have an independent machine that you deploy your container to. Jenkins can deploy the container to this machine using various plugins, or even as simply as just using ssh to login to the machine and execute some deployment scripts.
In the case of Kubernetes, you could do something as simple as having Jenkins execute kubectl
commands to apply manifest (still using the independent machine strategy I mentioned previously), or there are entire platforms to help you deploy your containers to Kubernetes, such as Spinnaker, Razee, etc.
Upvotes: 1