简体   繁体   中英

How to run a docker image in Jenkins

I know how to build a docker image in Jenkins. Basically, calling docker.build("foo") from my Jenkinsfile is the equivalent of executing, from the command line, docker build -t foo . .

My question is how I RUN the image? What's the equivalent of docker run foo , assuming that foo has a defined ENTRYPOINT ?

I'm familiar with docker.image('foo').inside() { ... } , which allows me to run a shell script or something inside the container, but that's not what I'm looking for. I want to run the container from it's ENTRYPOINT .

For running a Docker image from jenkinsfile you can use the below docker CLI commmand-

sh "docker run -it --entrypoint /bin/bash example"

It will start the docker container (run docker image) and you can ssh to the host where docker is running and can use docker ps command to list the running container.

You can probably have a look at .withRun -

Run a normal command OR use your entrypoint as argument -

docker.image('python:2.7').withRun('-u root --entrypoint /bin/bash') {
    sh 'pip install version'
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM