fff
fff

Reputation: 199

Docker shows authentication error when pushing to repository

I have a simple HelloWorld Spring Boot app in IntelliJ.

This is my code:

@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;
    }
}

This is my 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>

I follow this tutorial: https://spring.io/guides/gs/spring-boot-docker/

I want to deploy this app to docker, following the tutorial, I created a docker file in main/docker/Dockerfile

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"]

Then ran those commands in terminal of IntelliJ

mvn package docker:build -e

and it created successfully after tryings. When in linux termnal I run docker images, I see:

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

According to the tutorial, I need to push to that repo with this:

sudo docker push springio/hllowrlddckr

but it gives errors with or without 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

What is the error?

Upvotes: 0

Views: 507

Answers (1)

Marek J
Marek J

Reputation: 1374

As you can read in the mentioned tutorial:

You don’t have to push your newly minted Docker image to actually run it.

Error that you see is also explained in this tutorial: you are not authorized to push to frolvlad repository.

Upvotes: 1

Related Questions