&quot&quot" head \ https://registry-1.docker.io/v2/testcontainers/ryuk/manifests/0.3.0 \:noverizatiand \:nocratorized:不正确的用户名或密码;运行测试时

发布于 2025-01-27 01:18:12 字数 2163 浏览 5 评论 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桌面并使用Docker桌面记录了它,然后尝试使用CLI。

运行时 获取以下错误

com.github.dockerjava.api.exception.internalserervererrorexception:状态500:{“ message”:“ head” https://registry-1.docker.io/v2/testcontainers/testcontainers/ryifests/ryifests/manifests/0.3.0.0.3.0.3.0.3.0.3.0.3.0 “:未经授权:不正确的用户名或密码”} atrg.testcontainers.shaded.com.github.dockerjava.core.defaultinvocationbuilder.execute(defaultinvocationbuilder.java:247) 请访问org.testcontainers.shaded.com.github.dockerjava.core.defaultinvocationbuilder.lambda $ executeandstream $ 1(defaultinvocationbuilder.java:269) 在java.lang.thread.run(thread.java:748)

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


}

  • I have installed docker desktop and logged it using docker desktop And then try using cli.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

花开半夏魅人心 2025-02-03 01:18:12

这对我有帮助:

$ docker logout
$ docker login --username your_username_here

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

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

無心 2025-02-03 01:18:12
  1. 在命令提示符中运行命令netcfg -d,然后重新启动您的PC。
    这对我有用

参考
https://github.com/github.com/testcontcontainers/testcontcontcontcontcontcontcontcontcontcontcontcontcontcontcontainers-java/sissues/3422

  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

奢欲 2025-02-03 01:18:12

在M1 Mac上对我有用的修复程序是:

  1. 删除credsstore:desktop from〜/.docker/config.json
  2. Run docker login in终端中

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
财迷小姐 2025-02-03 01:18:12

以下解决方案在Win11上对我有用:

  1. 从Docker
  2. Open CMD
  3. 登录此命令 - Docker登录Index.docker.io
  4. 输入您的Docker登录/密码
  5. 享受

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文