2016-10-03 49 views
0

我一直試圖在我的Mac上構建我的Maven Spring Boot項目的Docker鏡像。Maven在Mac上與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 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_HOST的價值appers到正常泊塢窗命令做工精細。

我該怎麼做才能使碼頭工人在Mac上工作?

+0

https://github.com/spotify/docker- maven-plugin/issues/218 – Matt

+0

看起來,如果'docker-client'已經更新或者'DOCKER_HOST = unix:/// var/run/docker.sock',它與你設置的相同。你如何在Maven環境中設置'DOCKER_HOST'? – Matt

+0

我不知道如何在Maven環境中設置DOCKER_HOST。它是通過POM中的某些鍵完成的嗎? –

回答

1

我已經解決了這個問題,通過啓用我的普通用戶帳戶來運行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 
相關問題