“消息”:“头”https://registry-1.docker.io/v2/testcontainers/ryuk/manifests/0.3.0“:未授权:用户名或密码不正确”运行测试时

我在 Spring Boot 应用程序中添加了 testcontainer

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();
    }

}
  • 我已经安装了 docker desktop 并使用 docker desktop 记录了它然后尝试使用 cli。

运行时出现以下错误

com.github.dockerjava.api.exception.InternalServerErrorException: 状态 500: {"message":"head "https://registry-1.docker.io/v2/testcontainers/ryuk/manifests/0.3.0": 未授权:在 org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder.lambda$ executeAndStream$1(DefaultInvocationBuilder.java:269) 在 java.lang.Thread.run(Thread.java:748) Error message in the terminal

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

答案:

作者头像
  1. 在命令提示符中运行命令 netcfg -d 然后重新启动您的 PC。这对我有用

参考
https://github.com/testcontainers/testcontainers-java/issues/3422

作者头像

这帮助了我:

$ docker logout
$ docker login --username your_username_here

在这里找到它 - https://forums.docker.com/t/unauthorized-incorrect-username-or-password/35677/4