Jenkins Docker Failed To Download Plugin

Download

The content driving this site is licensed under the Creative Commons Attribution-ShareAlike 4.0 license. UI 13067fa / API 5723ad6 2021-10-04T12:03:33.000Z. Step 2: First, pull the official jenkins image from Docker repository. $ docker pull jenkins. Step 3: Next, run a container using this image and map data directory from the container to the host; e.g in the example below /var/jenkinshome from the container is mapped to jenkins/ directory from the current path on the host.

In this blog, we will integrate Jenkins with Docker so that we can have an automation to run the docker container directly from the Jenkins. We will create a freestyle and the pipeline job to run a docker image inside a container through Jenkins

If you want to see the video for this article, click here

If you do not know about Docker and the installation process, refer my docker article for the basic understanding and how to do the docker installation.

Prerequisite:

  1. Jenkins should be installed
  2. SSH setup between Jenkins and the remote server
  3. Docker should be installed on the server where you need to run a container and the user should be added to the docker group
  4. Setup SSH between Github and Jenkins if you want to use the SSH url instead of https url of your git repo

Freestyle Job in Jenkins

Let’s create a freestyle job in Jenkins to run a docker commands directly on the Jenkins server and then on the remote server. We don’t need to install the Docker plugin on the Jenkins.

Run Docker on Jenkins Server/Agent

We will create a freestyle job and the docker container will run inside a Jenkins server or the agent where job is actually running

File
  1. Create a freestyle job , select “Execute Shell” option under Build section and use the below commands.

2. This container will run on the Jenkins Server or if you are using agents then on the Jenkins agents

3. Run the job and see the output, you should be able to see the below output

Run Docker on Remote Host

We will create a freestyle job and the docker container will run on the remote hosts where your application should be deployed

  1. Create a freestyle job , select “Execute Shell” option under Build section and use the below commands
  2. Here, we will be using private/public IP of the remote server and the user for which we have established the SSH connection

3. Make sure to add jenkins user to the docker group on the remote hosts as well.

4. Output of the job

Pipeline Job in Jenkins

  1. Use this git repo
  2. Create a Jenkinsfile as shown below

Jenkins Docker Failed To Download Plugin For Chrome

3. Create a pipeline job and use this git repo and trigger the build

You should be able to success output and the pipeline job like this

Docker Troubleshooting

If you see the below error it means docker service is not running on the machine. Start the docker service and try the build again

5. If you see the below error “ Permission Denied”

then add jenkins user to the docker group and restart the jenkins service as shown below :

Congratulations, you have successfully learnt how to Integrate Jenkins with Docker and run the docker container in an automated fashion using CI/CD.

This plugin allows adding various Docker commands into your Jenkins Freestyle job as a build step.

If you would like to use Docker for dynamic node provisioning, you should check the Docker plugin.

Commands

Plugin currently support following commands:

  • commit changes in specified container
  • create new container from image
  • create image from Dockerfile
  • create exec command
  • kill container(s)
  • pull image from a repository
  • push image to a repository
  • remove container(s)
  • remove all containers
  • restart container(s)
  • start container(s)
  • stop container(s)
  • stop all containers
  • start/stop all containers created from specified image
  • start exec command

Build Variables

Some commands also export build variables, so that you can easily use them in subsequent build steps.

Variables exported by create and start commands:

Plugin

DOCKER_CONTAINER_IDS - IDs of created/started containers

DOCKER_IP_$HOSTNAME - IP of running container with hostname $HOSTNAME

When port binding is set up (in start command), the following environment variables are exported:

DOCKER_HOST_BIND_PORTS - contains comma separated list of ports to which are bound docker container ports

DOCKER_HOST_PORT_$SCHEMA_$PORT - which docker container port is bound to this port (e.g. DOCKER_HOST_PORT_TCP_80 would contain value 8080 in case that container port 8080 is bound to port 80 on host)

DOCKER_HOST_SOCKET_$SCHEMA_$PORT - host IP:PORT to which conatiner $PORT using $SCHEMA is bound. E.g. with following port binding 127.0.0.1:80:8080, container TCP port is 8080 is bound to host port 80 on loopback and DOCKER_HOST_SOCKET_TCP_8080 will contain 127.0.0.1:80.

Known limitations

Commands run without any issue only on master, on remote slaves some commands may fail execution. See JENKINS-24071 for details.

Build Nodes

Jenkins Docker Failed To Download Plugin Windows 10

The Docker service must be installed and running on nodes where you run the build.

Set Docker URL

In Jenkins global configuration, you need to specify Docker REST API URL.

Jenkins -> Manage Jenkins -> Configure System -> Docker Builder

  • Configure Docker server REST API URL
    • For Linux nodes, set the local socket unix:///var/run/docker.sock
    • For other nodes, you may need to set something like tcp://127.0.0.1:2375
  • Test the connection.

Commands

In the build area of ​​Jenkins Job, add the build step

There is a range of Docker Command options, roughly correlating with the Docker CLI commands.

Docker Pull

Fields

Failed
FieldDescription
Name of the image to pull (repository/image:tag)base name of the image
TagActual tag, e.g. 3.4.5 or latest
Registryhostname of registry used to store images e.g. mydocker.mycompany.com
Docker registry URLregistry URL to use for pull authentication, e.g. https://mydocker.mycompany.com
Registry Credentials...Choose correct credential here from the list...

Docker Tag

Fields

FieldDescription
Name of the image to tag (repository /image:tag)base name of the image
Target repository of the new tagdestination repository/image name e.g. dac/nodeynode
The tag to setActual destination tag, e.g. 3.4.5 or latest

Scenario 1: Tag a Dockerhub image with a local tag

Effective Docker command line

Settings

FieldValue
Name of the image to tag (repository /image:tag)library/node:8.9.4
Target repository of the new tagdac/nodeynode
The tag to set8.9.4

Result

Scenario 2: Tag a private repo image with a local tag

Effective Docker command line

Settings

FieldValue
Name of the image to tag (repository/image:tag)mydocker.mycompany.com/library/node:4.4.6
Target repository of the new tagdac/nodeynode
The tag to set4.4.6

Result

Download

Docker Push

Fields

FieldDescription
Name of the image to push (repository /image)base name of the image
TagActual tag, e.g. 3.4.5 or latest
Registryhostname of registry used to store images e.g. mydocker.mycompany.com
Docker registryregistry hostname to use for authentication, e.g. mydocker.mycompany.com
Registry Credentials...Choose correct credential here from the list...

Scenario 1: Push a local image to a private repo

Effective Docker command line

Settings

FieldValue
Name of the image to push (repository /image)dac/nodeynode
Tag4.4.6
Registrymydocker.mycompany.com
Docker registrymydocker.mycompany.com
Registry Credentials...Choose correct credential here from the list...

Result

  • Jenkins Plugin ID: docker-build-step

Uses components from Docker Commons Plugin which provides APIs for other Docker-related plugins

See License