Cannot use Docker file when using Jenkins CloudBees Docker Custom Build Environment Plugin

I tried using "Build in the docker container" with the option "Build from Dockerfile", following the guide from here the CloudBees Docker Custom Build Environment plugin

I installed the Dockerfile under the root of the workspace (/ var / lib / jenkins / jobs / lumi / workspace). Then, when the assembly starts, I got the error below. I think he was able to find the Dockerfile, but for some reason he was unable to create the image.

Build Docker image from ./Dockerfile ... $ docker build --tag b916af9f0b3e48425cb54c323d1a3adb749a72a1 --file Dockerfile /var/lib/jenkins/jobs/lumi/workspace The Dockerfile (Dockerfile) must be within the build context (/var/lib/jenkins/jobs/lumi/workspace) 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:116) at com.cloudbees.jenkins.plugins.docker_build_env.DockerfileImageSelector.prepareDockerImage(DockerfileImageSelector.java:47) at com.cloudbees.jenkins.plugins.docker_build_env.DockerBuildWrapper.setUp(DockerBuildWrapper.java:126) at hudson.model.Build$BuildExecution.doRun(Build.java:156) at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:537) 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:381) Finished: FAILURE 

The following is the Dockerfile content:

 FROM php:5.6.11-apache 

Thanks in advance.

+4
source share
4 answers

If you are currently in a directory with a Dockerfile, do the following:

 $ docker build --tag b916af9f0b3e48425cb54c323d1a3adb749a72a1 --file Dockerfile . 

Which is equivalent:

 $ docker build --tag b916af9f0b3e48425cb54c323d1a3adb749a72a1 . 

In both cases . indicates the context of the assembly - a set of directories and files that are sent to the Docker daemon. Use . just installs it in the current directory. Since the Dockerfile is in the current directory, it will be sent to the daemon.

The problem in your example is that it is looking for a Docker file in /var/lib/jenkins/jobs/lumi/workspace/Dockerfile . Presumably, the Dockerfile does not exist, but in your current directory. Since only files in the /var/lib/jenkins/jobs/lumi/workspace directory were sent to the Docker daemon, it does not have a Docker file to build with.

I understand this sounds a little strange. While this does not make sense, it is easiest to run your builds from a directory using the Dockerfile to avoid such problems.

(Also, do not put the Docker file in your home directory or the Download folder, as this will lead to a long wait, since all data is sent to the daemon).

0
source

I finally got the answer!

I had the same problem as now, and it is actually very stupid.

I assume that you checked "build inside Docker container" on the project configuration page. You must also specify the path where you made sure that the Dockerfile is inside the repository.

This is the point. If there is a Dockerfile in this path, the recording space next to the "Dockerfile" should be empty. I assume this space is to use a Dockerfile that is not inside the specified path. Without this, Jenkins will assume that your Docker file is in your specified space and he wonโ€™t worry about any other place.

Since I'm new to StackOverflow, I canโ€™t post a screenshot yet. But when I can, I will make it so that you have it, so that I can make my thoughts easier.

I sincerely hope this helps. I had an error message of the same type on the output, and now I can easily create my Docker images.

+4
source

Assuming you run this setup on a Jenkins slave machine.

enter image description here

$ {WORKSPACE} will set the docker context. This should solve the problems of your way.

0
source

It does not find the Docker file. If you are sure that you place the Dockerfile in the workspace, Jenkins can change the workspace depending on how the task is defined.

For example, the Git plugin can be configured to clear all files from the workspace. This will delete any Docker file that you manually placed there. Or you can configure it to check in a subdirectory that is not related to your Docker configuration.

Run the assembly, then look into the workspace and see if the Docker file is in the root of the workspace.

Also, if you manually enter values โ€‹โ€‹for the context path or Dockerfile file name, double-check that they accurately reflect what is actually in the workspace.

0
source

All Articles