John
John

Reputation: 176

How to run a docker command in Jenkins Build Execute Shell

I'm new to Jenkins and I have been searching around but I couldn't find what I was looking for.

I'd like to know how to run docker command in Jenkins (Build - Execute Shell):

Example: docker run hello-world

I have set Docker Installation for "Install latest from docker.io" in Jenkins Configure System and also have installed several Docker plugins. However, it still didn't work.

Can anyone help me point out what else should I check or set?

John

Upvotes: 5

Views: 18805

Answers (2)

Tires
Tires

Reputation: 1602

I came across another generic solution. Since I'm not expert creating a Jenkins-Plugin out of this, here the manual steps:

  1. Create/change your Jenkins (I use portainer) with environment variables DOCKER_HOST=tcp://192.168.1.50 (when using unix protocol you also have to mount your docker socket) and append :/var/jenkins_home/bin to the actual PATH variable
  2. On your docker host copy the docker command to the jenkins image "docker cp /usr/bin/docker jenkins:/var/jenkins_home/bin/"
  3. Restart the Jenkins container

Now you can use docker command from any script or command line. The changes will persist an image update.

Upvotes: 1

Mark O'Connor
Mark O'Connor

Reputation: 77971

One of the following plugins should work fine:

I normally run my builds on slave nodes that have docker pre-installed.

Upvotes: 4

Related Questions