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

nue99wik  于 2023-06-21  发布在  Docker
关注(0)|答案(3)|浏览(175)

我在Sping 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“:unauthorized:错误的用户名或密码”} 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)x1c 0d1x

col17t5w

col17t5w1#

1.在命令提示符下运行netcfg -d命令,然后重新启动PC。这对我很有效
参考文献
https://github.com/testcontainers/testcontainers-java/issues/3422

nsc4cvqm

nsc4cvqm2#

这帮助了我:

$ docker logout
$ docker login --username your_username_here

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

yc0p9oo0

yc0p9oo03#

我在M1 Mac上使用的修复方法是:
1.从~/. docker/config. json中删除credsStore:desktop
1.在终端中运行docker login

相关问题