Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is happening when docker-maven plugin tries to build image?

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

like image 294
kevin Avatar asked Jan 12 '16 16:01

kevin


People also ask

Can Maven build Docker images?

Jib is a Maven and Gradle plugin for creating Docker images for Java applications. A benefit is that it does not require Docker to be installed locally* which can be useful for Continuous Integration / build server — the jib-maven-plugin will build and push the image straight to the Docker registry of choice.

What is the use of Docker Maven plugin?

This plugin allows you to manage Docker images and containers from your pom. xml. Run Java EE 7 Applications as a Docker Container using Maven! Tests can be invoked using Arquillian, again using Maven.


2 Answers

As mentioned above by Rajith Delantha, this solved the problem for me:

Add: DOCKER_OPTS=' -G jenkins' directly in /etc/default/docker.

Then restart docker service by sudo service docker restart.

like image 147
Aaron Zhao Avatar answered Sep 27 '22 16:09

Aaron Zhao


This can be resolved by adding DOCKER_HOST environment variable in Jenkins.

Setup your docker daemon like this:

[/etc/sysconfig/docker]
OPTIONS="-H tcp://127.0.0.1:4243"

Jenkins Jobs (Inject environment variables):

DOCKER_HOST=tcp://127.0.0.1:4243
like image 26
Aditya Sirna Avatar answered Sep 27 '22 16:09

Aditya Sirna