What is happening when docker-maven plugin tries t

2019-04-04 06:06发布

I am running Jenkins in a docker container and Jenkins tries to run my maven build. As part of the build, the docker maven plugin instructs it to build a docker image.

That part of the POM is below.

<plugin>
    <groupId>com.spotify</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>0.3.8</version>
    <configuration>
        <imageName>example</imageName>
        <baseImage>java:latest</baseImage>
        <skipDockerBuild>false</skipDockerBuild>
        <cmd>["java", "-jar", "myLogThread-jar-with-dependencies.jar"]</cmd>
        <resources>
            <resource>
                <directory>target/</directory>
                <include>config.properties</include>
            </resource>
            <resource>
                <directory>${project.build.directory}</directory>
                <include>myLogThread-jar-with-dependencies.jar</include>
            </resource>
        </resources>
    </configuration>
</plugin>

The maven build runs until it attempts to build the image, at which point the following error message is spat out:

[INFO] Building image example
[INFO] I/O exception (java.io.IOException) caught when processing request to {}->unix://localhost:80: Permission denied

I can go into the correct directory and the Dockerfile is there.

I can also run sudo docker build . and it will build the image with no issues.

Why is the maven build failing? What request is being made to localhost:80? How can I correct this so that maven can build my image?

Note: I have mounted the docker socket and binary in this container

7条回答
我只想做你的唯一
2楼-- · 2019-04-04 06:49

I was able to solve the problem by combining elements of both upvoted answers.

Set options to use different port in /etc/default/docker.

DOCKER_OPTS="-H tcp://127.0.0.1:4243"

Restart the Docker daemon.

sudo service docker restart

Then build your package.

export DOCKER_HOST=tcp://127.0.0.1:4243
mvn clean package docker:build
查看更多
登录 后发表回答