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

前端 未结 8 1900
[愿得一人]
[愿得一人] 2021-02-12 20:40

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.

相关标签:
8条回答
  • 2021-02-12 20:55

    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
    
    0 讨论(0)
  • 2021-02-12 20:56

    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>
    
    0 讨论(0)
  • 2021-02-12 20:58

    I met the issue at bamboo-agent, but I assume the same holds for jenkins.

    Add the user running maven to the docker group. Then restart docker AND the service running maven. Group changes are not loaded while the services are running. So in my case:

    sudo groupadd docker # if it does not exist
    sudo usermod -a -G docker bamboo-user
    sudo systemctl restart docker.service
    sudo systemctl restart bamboo-agent.service
    
    0 讨论(0)
  • 2021-02-12 21:01

    I had a similar issue when I didn't have the docker daemon running - restart the Docker toolbox and it looks much happier now

    0 讨论(0)
  • 2021-02-12 21:12

    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
    
    0 讨论(0)
  • 2021-02-12 21:13

    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

    0 讨论(0)
提交回复
热议问题