I/O exception(java.io.IOException)caught when processing request to{}->unix://localhost:80:No such file or directory -when build image frm Dockerfile

huangapple go评论72阅读模式
英文:

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>

In Jenkins Docker settings:
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 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 [&quot;mvn&quot;, &quot;package&quot;]


FROM tomcat:9
EXPOSE 8087
COPY /app/target/*.war /usr/local/tomcat/webapps/
 CMD [&quot;catalina.sh&quot;,&quot;run&quot;]

And the plugin part of pom.xml is :

 &lt;plugins&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
                &lt;configuration&gt;
                    &lt;mainClass&gt;com.example.restcurd.RestcurdApplication&lt;/mainClass&gt;
                &lt;/configuration&gt;
            &lt;/plugin&gt;

            &lt;plugin&gt;
                &lt;groupId&gt;com.spotify&lt;/groupId&gt;
                &lt;artifactId&gt;dockerfile-maven-plugin&lt;/artifactId&gt;
                &lt;version&gt;1.4.10&lt;/version&gt;
                &lt;executions&gt;
                    &lt;execution&gt;
                        &lt;id&gt;build&lt;/id&gt;
                        &lt;phase&gt;package&lt;/phase&gt;
                        &lt;goals&gt;
                            &lt;goal&gt;build&lt;/goal&gt;
                          
                        &lt;/goals&gt;
                    &lt;/execution&gt;
                &lt;/executions&gt;
                &lt;configuration&gt;
                    &lt;repository&gt;pomkiticat/${project.name}&lt;/repository&gt;
                    &lt;tag&gt;${project.version}&lt;/tag&gt;
                    &lt;skipDockerInfo&gt;true&lt;/skipDockerInfo&gt;
                    &lt;pullNewerImage&gt;false&lt;/pullNewerImage&gt;
                &lt;/configuration&gt;
            &lt;/plugin&gt;
        &lt;/plugins&gt;

In Jenkins docker setting is :
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 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 -&gt; [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:&lt;user name or ID&gt;: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.

huangapple
  • 本文由 发表于 2020年7月29日 15:57:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/63148930.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定