I want to create a image for maven project using Dockerfile in Jenkins. This is a spring boot project. I have run the Jenkins as docker container. I am using windows 10.
My dockerfile is :
FROM maven:3.5-jdk-8-alpine
WORKDIR /app
COPY pom.xml /app/
COPY Dockerfile /app/
RUN ["mvn", "package"]
FROM tomcat:9
EXPOSE 8087
COPY /app/target/*.war /usr/local/tomcat/webapps/
CMD ["catalina.sh","run"]
And the plugin part of pom.xml is :
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.example.restcurd.RestcurdApplication</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.10</version>
<executions>
<execution>
<id>build</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
<configuration>
<repository>pomkiticat/${project.name}</repository>
<tag>${project.version}</tag>
<skipDockerInfo>true</skipDockerInfo>
<pullNewerImage>false</pullNewerImage>
</configuration>
</plugin>
</plugins>
In Jenkins docker setting is :
I have also select the option Expose daemon on tcp://localhost:2375 without TLS
in docker desktop .
But I am getting the error
[0m[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 16:05 min
[INFO] Finished at: 2020-07-29T06:58:10Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.spotify:dockerfile-maven-plugin:1.4.10:build (default) on project restcurd: Could not build image: java.util.concurrent.ExecutionException: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: java.io.IOException: No such file or directory -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
I found solution for the problem. I get some solution i.e. to set the Docker Host Uri . I have already set it and attached the image above .
How Can I solve the problem? Thanks in advance.
It happens when a process tries to write to the docker daemon socket but it lacks of permissions.
Check that /var/run/docker.sock
is accessible for the user that tries to create the docker image. In particular, by default only root and the group has rights to write to docker.socket, so try executing chmod o+w /var/run/docker.sock
in order to allow others to write into the docker daemon socket and then the issue should be gone.
I faced with this error too with ubuntu 22.4 and docker desktop. In my case the problem was in "docker context". Maven can't use these contexts and use standard (unix:///var/run/docker.sock or unix://localhost:80). But docker desktop uses your home directory by default and there is not docker engine on standard socket. You can see your contexts by command:
docker context ls
In my case the answer is:
NAME | DESCRIPTION | DOCKER ENDPOINT |
---|---|---|
default * | Current DOCKER_HOST based configuration | unix:///var/run/docker.sock |
desktop-linux | Docker Desktop | unix:///home/sergey/.docker/desktop/docker.sock |
To fix it all you need is set DOCKER_HOST to your "desktop-linux" endpoint, in my case:
export DOCKER_HOST=unix:///home/sergey/.docker/desktop/docker.sock
And "mvn dockerfile:build" starts working! You can put the DOCKER_HOST var in /etc/environment.
Maybe I answered on a bit other question but I believe this might help someone. This helped me to find the solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With