How to run a docker command in Jenkins Build Execute Shell

Viewed 17270

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

2 Answers

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.

Related