I've been blocked since yesterday and need some help. I tried to use both jenkins docker-plugin and docker-plugin-step to build docker image from a dockerfile.
However, when I try to run the jenkins job, it gives me the following exception:
Docker Build
Docker Build : build with tag jdubois/jhipster-docker:Gateway_Jenkins_V1 at path /home/javateam/DockerfileGateway
ERROR: Build step failed with exception
java.lang.NullPointerException: config was not specified
at shaded.com.google.common.base.Preconditions.checkNotNull(Preconditions.java:226)
at com.github.dockerjava.core.DockerClientImpl.<init>(DockerClientImpl.java:36)
at com.github.dockerjava.core.DockerClientImpl.getInstance(DockerClientImpl.java:52)
at com.github.dockerjava.core.DockerClientBuilder.getInstance(DockerClientBuilder.java:29)
at com.nirima.jenkins.plugins.docker.builder.DockerBuilderPublisher$Run$1.invoke(DockerBuilderPublisher.java:144)
at com.nirima.jenkins.plugins.docker.builder.DockerBuilderPublisher$Run$1.invoke(DockerBuilderPublisher.java:139)
at hudson.FilePath.act(FilePath.java:991)
at hudson.FilePath.act(FilePath.java:969)
at com.nirima.jenkins.plugins.docker.builder.DockerBuilderPublisher$Run.buildImage(DockerBuilderPublisher.java:139)
at com.nirima.jenkins.plugins.docker.builder.DockerBuilderPublisher$Run.run(DockerBuilderPublisher.java:89)
at com.nirima.jenkins.plugins.docker.builder.DockerBuilderPublisher.perform(DockerBuilderPublisher.java:180)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.build(MavenModuleSetBuild.java:915)
at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.doRun(MavenModuleSetBuild.java:866)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:537)
at hudson.model.Run.execute(Run.java:1744)
at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:531)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:374)
Build step 'Build / Publish Docker Containers' marked build as failure
Finished: FAILURE
The following is the dockerfile content:
#Basic images for Gateway MS
FROM jdubois/jhipster-docker:Gateway_Jenkins_V1
#Fetch last Gateway MS version from gitlab and run it
RUN cd /home/jhipster/DockerJenkinsGateway && \
git pull origin master
# expose the working directory, the Tomcat port, the BrowserSync ports, the SSHD port, and run SSHD
VOLUME ["/jhipster"]
EXPOSE 8080 3000 3001 22
CMD /usr/sbin/sshd -D
What am doing wrong??
Another option is to use the shell provided by Jenkins as a build step, and just build the Docker image using the command-line arguments you would normally use in that shell script.
That's what we do on our build server and it gives us fine grained control over things like versioning and which image/tag to push to Dockerhub.
If you are using Jenkins 2.0 or above then Jenkins give you an option to build pipeline as the code and you can easily integrate docker and its repositories.
Go to --> new item --> select multi branch pipeline option and you will see the option to connect to docker via Jenkins.
Let me know in case of more details.
Related
Hello i want to build some maven projects in docker.
While the build process some more docker containers will be spawned so i want to isolate them inside... docker.
for Example:
Develop-branch[database-container, core-container]
Feature(1..n)[database-container, core-container]
I tried to use Jenkins docker plugin and configured the linux-server as cloud using unix socket.
For the building container i use docker:dind and installed inside maven java and git.
FROM docker:dind
RUN apk add openjdk11 maven git
compailing is working but if it comes to the
build stepp calling docker i got the Error:
[ERROR] DOCKER> Cannot create docker access object [No such file or directory]
When I was trying to run a Jenkins pipeline project, it failed giving this message under the "docker pull node:6-alpine":
<.jenkins/workspace/simple-node-js-react-npm-app#tmp/durable-431710c5/script.sh: line 2: docker: command not found
script returned exit code 127>
I have no idea what's going on here, and I couldn't access the directory mentioned in the error. I am pretty new to Jenkins.
As mentioned here, using the JENKINS Docker Plugin or JENKINS Docker Pipeline Plugin would not be enough to allow a node to use docker.
You still need to install docker on the node itself.
Please follow below steps:
Install the docker engine (yum install docker) on server where Jenkins is running.
Verify docker is installed: run command which docker.
Click on Jenkins manage plugin and install docker plugin.
I am using Jenkins Custom Build Environment Plugin (1.6.5) to build images from a Dockerfile inside the slave container checked in along with the source code.
Slaves running on Docker version 1.9.1, build ab77bde/1.9.1
My Dockerfile is as below which is able to pull from official ubuntu image but fails to pull from official node.js image -
FROM node:boron
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
On Jenkins job execution I get below failure -
$ docker build --file /data/name-jenkins/workspace/TestJobs/BuildFromSCM/Dockerfile /data/name-jenkins/workspace/TestJobs/BuildFromSCM
Sending build context to Docker daemon 149.5 kB
Sending build context to Docker daemon 149.5 kB
Step 1 : FROM node:boron
Trying to pull repository registry.access.redhat.com/node ... failed
Trying to pull repository docker.io/library/node ... failed
Authentication is required.
FATAL: Failed to build docker image from project Dockerfile
java.lang.RuntimeException: Failed to build docker image from project Dockerfile
at com.cloudbees.jenkins.plugins.docker_build_env.Docker.buildImage(Docker.java:134)
at com.cloudbees.jenkins.plugins.docker_build_env.DockerfileImageSelector.prepareDockerImage(DockerfileImageSelector.java:46)
at com.cloudbees.jenkins.plugins.docker_build_env.DockerBuildWrapper.setUp(DockerBuildWrapper.java:169)
at hudson.model.Build$BuildExecution.doRun(Build.java:156)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:534)
at hudson.model.Run.execute(Run.java:1741)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:410)
Finished: FAILURE
I am able to build the Docker image on my local machine though. I confirmed that the Jenkins slave user has sudo permissions.
I found an issue in .docker/config.json on my slave machine where I accidentally set my dockerhub credentials which caused in failure in pulling public images with a generic user I was using to build Jenkins job.
{
"ServerURL": "https://index.docker.io/v1",
"Username": "myusername",
"Secret": "passw0rd1"
}
You may need a certificate of the docker-hub, which is a ca.crt file put in:
/etc/docker/certs.d/
I've got a jenkins declarative pipeline build that runs gradle and uses a gradle plugin to create a docker image. I'm also using a dockerfile agent directive, so the entire thing runs inside a docker container. This was working great with jenkins itself installed in docker (I know, that's a lot of docker). I had jenkins installed in a docker container on docker for mac, with -v /var/run/docker.sock:/var/run/docker.sock (DooD) per https://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/. With this setup, the pipeline docker agent ran fine, and the docker build command within the pipeline docker agent ran fine as well. I assumed jenkins also mounted the docker socket on its inner docker container.
Now I'm trying to run this on jenkins installed on an ec2 instance with docker installed properly. The jenkins user has the docker group as its primary group. The jenkins user is able to run "docker run hello-world" successfully. My pipeline build starts the docker agent container (based on the gradle image with various things added) but when gradle attempts to run the docker build command, I get the following:
* What went wrong:
Execution failed for task ':docker'.
> Docker execution failed
Command line [docker build -t config-server:latest /var/lib/****/workspace/nfig-server_feature_****-HRUNPR3ZFDVG23XNVY6SFE4P36MRY2PZAHVTIOZE2CO5EVMTGCGA/build/docker] returned:
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
Is it possible to build docker images inside a docker agent using declarative pipeline?
Yes, it is.
The problem is not with Jenkins' declarative pipeline, but how you're setting up and running things.
From the error above, looks like there's a missing permission which needs to be granted.
Maybe if you share what your configuration looks like and how your're running things, more people can help.
I want to create a automatic docker image through Jenkins once build got success.
I tried by providing docker commands in execute shell but throwing command not found error.If this is not right way how to achieve this in Windows 10.
Error:
................
................
12 passing (81ms)
+ docker build -t snapshot .
C:\WINDOWS\TEMP\jenkins6038297422360146327.sh: line 4: docker: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE
Even after installing docker inside jenkins it is not picking my docker url
Docker inside jenkins
Complete error of Docker URL
Created a new vm with TLS false:
docker-machine create -d virtualbox --engine-opt tlsverify=false node2
to check TLS is made false i ran below command
docker-machine env node2
here DOCKER_TLS_VERIFY = "1",however in the documentation it is mentioned DOCKER_TLS_VERIFY = "0" should be zero whether my machine now TLS enabled or not how can i confirm my machine is TLS false??
The shell you configured in your Jenkins job is executed by Jenkins executor on Jenkins machine(or Jenkins Slave machine if you're using Jenkins the Master-Slave way), so whatever command you would like to use, it must be installed correctly and in the PATH of the target machine, just like you execute command on terminal manually.
So the error message is self-explained now:
C:\WINDOWS\TEMP\jenkins6038297422360146327.sh: line 4: docker: command not found
which means you have not installed docker on your Jenkins machine, you need to install and configure it firstly.
Additionally, you may want to have a look at Docker build step plugin for Jenkins.
install docker on jenkins. Jenkins does not know about docker.
If you don't need to run Docker on the same server than Jenkins I found that downloading a Docker Client was better than using the Jenkins Plugin.
You can find the latest version here: https://download.docker.com/win/static/stable/x86_64/
Then just call the docker command with --host 192.168.99.100. It should work and build the image on the Docker Server 192.168.99.100