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

10,013

Solution 1

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.

Solution 2

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

Solution 3

after making sure docker ps works from the same user that runs mvn I still had the same problem. it looks like a bug due to special characters in the image name. I resolved it by removing the dash sign (-) (or any special characters) from the docker image name.

try set the repository to deferent name and check.

            <configuration>
                <repository>somename</repository>                    
            </configuration>

Solution 4

I had the same problem, but in my local machine.

I've got it after reading this comment in Github thread: https://github.com/docker/compose/issues/1214#issuecomment-256774629

It says:

Solution (from https://docs.docker.com/engine/installation/linux/debian/, does not only work with Debian):

Add the docker group if it doesn't already exist.

sudo groupadd docker

Add the connected user "${USER}" to the docker group. Change the user name to match your preferred user. You may have to logout and log back in again for this to take effect.

sudo gpasswd -a ${USER} docker

Restart the Docker daemon.

sudo service docker restart

Share:
10,013

Related videos on Youtube

kevin
Author by

kevin

Updated on June 22, 2022

Comments

  • kevin
    kevin almost 2 years

    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

    • wholladay
      wholladay about 8 years
      Did you ever figure this out? I'm having the same issue.