0

概括

我正在尝试使用该docker-java库,但是在尝试提取图像时遇到了问题。我正在尝试从 ECR 上的私有存储库中提取。

我试过的

我一直在尝试的大部分实现都来自以下问题:
Pulling image from Amazon ECR using docker-java

不同之处在于我在 Kotlin 中实现它。我正在 MacOS 上开发。

我可以正常登录,因为我在执行时得到“登录成功” dockerClient.authCmd()

代码

        val awsCredentialsProvider: AWSCredentialsProvider = 
                DefaultAWSCredentialsProviderChain()
        val ecrClient = AmazonECRClientBuilder.standard()
                .withRegion(Regions.EU_WEST_2)
                .withCredentials(awsCredentialsProvider)
                .build()

        val getAuthTokenRequest = GetAuthorizationTokenRequest()
        val registryIds = ArrayList<String>()
        registryIds.add(registryId)
        getAuthTokenRequest.setRegistryIds(registryIds)

        val getAuthTokenResult = ecrClient.getAuthorizationToken(getAuthTokenRequest)
        val authData = getAuthTokenResult.authorizationData[0]
        val userPassword = StringUtils.newStringUtf8(Base64.decode(authData.authorizationToken))
        val user = userPassword.substring(0, userPassword.indexOf(":"))
        val password = userPassword.substring(userPassword.indexOf(":")+1)

        val config = DefaultDockerClientConfig.createDefaultConfigBuilder()
            config.withDockerTlsVerify(false)
            config.withRegistryUsername(user)
            config.withRegistryPassword(password)
            config.withRegistryUrl(authData.proxyEndpoint)
            config.build()

        //Docker client
        val dockerClient = DockerClientBuilder.getInstance(config)
            .withDockerCmdExecFactory(JerseyDockerCmdExecFactory())
            .build()

        val response = dockerClient.authCmd().exec()
        println(response.status)

        val pullImageCmd = dockerClient
                .pullImageCmd(nameOfRepository)
                .withAuthConfig(dockerClient.authConfig())
                .withRepository(nameOfRepository)

        pullImageCmd
                .exec(PullImageResultCallback())
                .awaitCompletion()

结果

我收到以下错误:

Caused by: com.github.dockerjava.api.exception.InternalServerErrorException: {"message":"Get https://registry-1.docker.io/v2/{name_of_repo}/tags/list: unauthorized: incorrect username or password"}

registry-1.docker.io/v2/URI 中不应该是我自己的仓库吗?有人可以对我遇到的问题有所了解吗?

4

0 回答 0