Docker在推送到存储库时显示身份验证错误

时间:2016-08-25 09:52:31

标签: docker

我在IntelliJ中有一个简单的HelloWorld Spring Boot应用程序。

这是我的代码:

@Configuration
@ComponentScan
@EnableAutoConfiguration
@SpringBootApplication
public class App extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(App.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}


//takes input and navigates to that address
@RestController
class GreetingController {

    @RequestMapping("/hello/{name}")
    String hello(@PathVariable String name) {
        return "Hello, welcome " + name + "!";
    }
}

@RestController
class IndexController implements ErrorController {

    private static final String PATH = "/error";

    @RequestMapping(value = PATH)
    public String error() {
        return "You wanted to go to invalid URL. Please check again.";
    }

    @Override
    public String getErrorPath() {
        return PATH;
    }
}

这是我的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>hllowrlddckr</groupId>
    <artifactId>hllowrlddckr</artifactId>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.0.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

<properties>
<docker.image.prefix>springio</docker.image.prefix>
    <java.version>1.8</java.version>
</properties>

<build>
<plugins>
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
    <plugin>
        <groupId>com.spotify</groupId>
        <artifactId>docker-maven-plugin</artifactId>
        <version>0.2.3</version>
        <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>
    </plugin>
</plugins>
</build>


</project>

我遵循本教程:https://spring.io/guides/gs/spring-boot-docker/

我想将此应用程序部署到docker,按照教程,我在main / docker / Dockerfile中创建了一个docker文件

FROM frolvlad/alpine-oraclejdk8:slim
VOLUME /tmp
ADD sudo-1.0-SNAPSHOT.jar app.jar
RUN sh -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

然后在IntelliJ终端中运行这些命令

  

mvn包docker:build -e

并且在尝试后成功创建。在linux termnal中我运行docker图像时,我看到:

docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
springio/hllowrlddckr        latest              0aa30f27c704        40 seconds ago      195.3 MB

根据教程,我需要用这个来推送回购:

sudo docker push springio/hllowrlddckr

但是无论有没有sudo都会出错:

sudo docker push springio/hllowrlddckr
The push refers to a repository [docker.io/springio/hllowrlddckr]
caa29c22a27c: Preparing 
04e6743be3df: Preparing 
f3d2c9a5ee9f: Preparing 
017f469bdc32: Preparing 
4fe15f8d0ae6: Preparing 
unauthorized: authentication required

错误是什么?

1 个答案:

答案 0 :(得分:1)

正如您在上述tutorial中所述:

  

您不必将新创建的Docker镜像推送到实际运行它。

您看到的错误也在本教程中进行了解释:您无权推送到frolvlad存储库。