Maven与Mac上的Docker守护进程通信的正确设置是什么?

时间:2016-10-03 23:04:38

标签: maven docker docker-build

我一直在尝试在我的Mac上构建我的Maven spring boot项目的Docker镜像。

这是我的构建部分:

<build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
             </executions>
      </plugin>
      <plugin>
  <groupId>com.spotify</groupId>
  <artifactId>docker-maven-plugin</artifactId>
       <configuration>
                    <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
                    <dockerDirectory>src/main/docker</dockerDirectory>
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>${project.build.directory}</directory>
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                    </resources>
                </configuration>
  <executions>
    <execution>
      <id>build-image</id>
      <phase>package</phase>
      <goals>
        <goal>build</goal>
      </goals>
    </execution>
    <execution>
      <id>tag-image</id>
      <phase>package</phase>
      <goals>
        <goal>tag</goal>
      </goals>
      <configuration>
        <image>my-image</image>
        <newName>registry.example.com/my-image</newName>
      </configuration>
    </execution>
  </executions>
</plugin>
    </plugins>
  </build>

当我运行此命令时:mvn -X package docker:build

我收到此错误:

 [ERROR] Failed to execute goal 
com.spotify:docker-maven-plugin:0.4.13:build (build-image) 
on project Spring-Boot-ReceiverAPI: Exception caught: 
Request error: 
POST unix://localhost:80/build?t=uptake/Spring-Boot-ReceiverAPI: 500: HTTP 500 Internal Server Error -> [Help 1]

这是我的DOCKER_HOST:

echo $DOCKER_HOST
unix:///private/var/run/docker.sock

所有其他docker命令运行良好:

docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
<none>                       <none>              384ed96af950        4 hours ago         640.9 MB
java                         8                   96cddf5ae9f1        10 days ago         640.9 MB
containersol/minimesos-cli   0.10.2              0f8fd0fee007        8 weeks ago         133.7 MB

Docker守护程序显然正在运行,并且DOCKER_HOST的值可以正常用于正常的Docker命令。

如何使Docker构建在Mac上运行?

1 个答案:

答案 0 :(得分:0)

我已经通过启用常规用户帐户来运行docker命令而不使用sudo来解决此问题。 这是POM的构建部分:

<build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
             </executions>
      </plugin>
      <plugin>
  <groupId>com.spotify</groupId>
  <artifactId>docker-maven-plugin</artifactId>
       <configuration>
                    <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
                    <dockerDirectory>src/main/docker</dockerDirectory>
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>${project.build.directory}</directory>
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                    </resources>
                </configuration>
  <executions>
    <execution>
      <id>build-image</id>
      <phase>package</phase>
      <goals>
        <goal>build</goal>
      </goals>
    </execution>
    <execution>
      <id>tag-image</id>
      <phase>package</phase>
      <goals>
        <goal>tag</goal>
      </goals>
      <configuration>
        <image>api</image>
        <newName>registry.example.com/api</newName>
      </configuration>
    </execution>
  </executions>
</plugin>
    </plugins>
    <resources>       
        <resource>
            <directory>${basedir}/src/main/docker</directory>
            <filtering>true</filtering>
            <includes>
                <include>Dockerfile</include>
            </includes>
        </resource>
    </resources>
  </build>

这是命令,在常规用户帐户下运行正常:

mvn -X package docker:build