Gopal
Gopal

Reputation: 71

"message":"Head \"https://registry-1.docker.io/v2/testcontainers/ryuk/manifests/0.3.0\": unauthorized: incorrect username or password" when run test

I have added testcontainer in spring boot app

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@SpringBootTest
@Testcontainers
@AutoConfigureMockMvc
class ProductServiceApplicationTests {

    @Container
    static MongoDBContainer mongoDBContainer = new MongoDBContainer("mongo:4.4.2");

    @Autowired
    private MockMvc mockMvc;
    @Autowired
    private ObjectMapper objectMapper;

    @DynamicPropertySource
    static void setProperties(DynamicPropertyRegistry dynamicPropertyRegistry) {
        dynamicPropertyRegistry.add("spring.data.mongodb.uri",mongoDBContainer::getReplicaSetUrl);
    }

    @Test
    void shouldCreateProduct() throws Exception {

        ProductRequest productRequest = getProductRequest();
        String productRequestString = objectMapper.writeValueAsString(productRequest);
        mockMvc.perform(MockMvcRequestBuilders.post("/api/product")
                .contentType(MediaType.APPLICATION_JSON)
                .content(productRequestString)
        ).andExpect(status().isCreated()) ;
    }

    private ProductRequest getProductRequest() {
        return ProductRequest.builder()
                .name("Iphone 13")
                .description("Iphone 13")
                .price(BigDecimal.valueOf(1200))
                .build();
    }


}

When Running it Getting the below error

com.github.dockerjava.api.exception.InternalServerErrorException: Status 500: {"message":"Head "https://registry-1.docker.io/v2/testcontainers/ryuk/manifests/0.3.0": unauthorized: incorrect username or password"} at org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder.execute(DefaultInvocationBuilder.java:247) at org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder.lambda$executeAndStream$1(DefaultInvocationBuilder.java:269) at java.lang.Thread.run(Thread.java:748) Error message in the terminal

Upvotes: 4

Views: 5648

Answers (4)

Nikolay
Nikolay

Reputation: 1

The following solution worked for me on Win11:

  1. Sign out from Docker
  2. open cmd
  3. put this command - docker login index.docker.io
  4. enter your login/password for Docker
  5. Enjoy

Upvotes: 0

Leonid
Leonid

Reputation: 41

The fix that worked for me on an M1 Mac was:

  1. remove credsStore:desktop from ~/.docker/config.json
  2. run docker login in terminal

Upvotes: 0

programmer Kazarin
programmer Kazarin

Reputation: 61

This helped me:

$ docker logout
$ docker login --username your_username_here

Found it here - https://forums.docker.com/t/unauthorized-incorrect-username-or-password/35677/4

Upvotes: 4

Gopal
Gopal

Reputation: 71

  1. Run the command netcfg -d in Command Prompt then restart your PC. This worked for me

Reference
https://github.com/testcontainers/testcontainers-java/issues/3422

Upvotes: 1

Related Questions