英文:
I/O exception(java.io.IOException)caught when processing request to{}->unix://localhost:80:No such file or directory -when build image frm Dockerfile
问题
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 a 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>
I have also selected the option Expose daemon on tcp://localhost:2375 without TLS
in Docker Desktop.
But I am getting the error:
[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 a solution for the problem. I got some solutions, 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.
英文:
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.
答案1
得分: 11
当一个进程尝试写入到Docker守护程序套接字,但缺乏权限时会发生这种情况。
请检查/var/run/docker.sock
是否对尝试创建Docker镜像的用户可访问。特别是,默认情况下只有root用户和组具有写入docker.socket的权限,因此尝试执行chmod o+w /var/run/docker.sock
以允许其他用户写入到Docker守护程序套接字,然后问题应该解决了。
英文:
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.
答案2
得分: 0
这在Fedora上对我有效:
export DOCKER_HOST=unix:///var/run/docker.sock
service docker restart
mvn clean install -DskipTests
英文:
This worked for me on Fedora
export DOCKER_HOST=unix:///var/run/docker.sock
service docker restart
mvn clean install -DskipTests
答案3
得分: 0
sudo setfacl --modify user:<用户名或ID>:rw /var/run/docker.sock
英文:
worked for me:
sudo setfacl --modify user:<user name or ID>:rw /var/run/docker.sock
答案4
得分: 0
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.
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论