Spotify dockerfile无法推送图像,资源已定义

时间:2019-06-02 09:11:47

标签: spring-boot docker dockerfile spotify-docker-client

我正在像这样使用Spotify Dockerfile maven插件

<plugins>
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>dockerfile-maven-plugin</artifactId>
                <version>1.4.10</version>
                <executions>
                    <execution>
                        <id>default</id>
                        <goals>
                            <goal>build</goal>
                            <goal>push</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <username>myUserName</username>
                    <password>myPassword</password>
                    <repository>dockerhubUsername/dockerhubRepo</repository>
                    <tag>latest</tag>
                    <buildArgs>
                        <JAR_FILE>${project.artifactId}.jar</JAR_FILE>
                    </buildArgs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>

因此,每当我使用mvn deploy进行构建时,都会出现此错误

[ERROR] Failed to execute goal com.spotify:dockerfile-maven-plugin:1.4.10:push (default) on project nepse-sim: Could not push image: denied: requested access to the resource is denied -> [Help 1]

我已经在配置中指定了我的dockerhub用户名和密码,但是仍然出现此错误。任何帮助,将不胜感激。谢谢

1 个答案:

答案 0 :(得分:1)

首先,不要将凭据放在pom.xml中,因为它将在git或您正在使用的任何内容中。因此,请将您的凭据添加到.m2文件夹内的settings.xml中。

<server>
    <id>docker.io</id>
    <username>xxxxx</username>
    <password>xxxxxx</password>
</server>

如下所示在pom.xml中更改您的配置标签-

<configuration>
    <repository>dockerhubUsername/dockerhubRepo</repository>
    <tag>${project.version}</tag>
    <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
    <buildArgs>
        <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
    </buildArgs>
</configuration>

然后它应该工作。