0

我正在使用这样的 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 用户名和密码,但我仍然收到此错误。任何帮助,将不胜感激。谢谢

4

1 回答 1

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>

然后它应该工作。

于 2020-02-01T22:45:26.207 回答