Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Docker 詹金斯:从奴隶推到ECR_Docker_Jenkins_Jenkins Plugins_Cloudbees_Amazon Ecr - Fatal编程技术网

Docker 詹金斯:从奴隶推到ECR

Docker 詹金斯:从奴隶推到ECR,docker,jenkins,jenkins-plugins,cloudbees,amazon-ecr,Docker,Jenkins,Jenkins Plugins,Cloudbees,Amazon Ecr,我正在用spotify的maven插件构建一个docker容器,然后尝试推送到ecr 这是在使用cloudbees插件登录后发生的 这就像詹金斯大师身上的符咒。 但在奴隶身上我得到: no basic auth credentials Build step 'Docker Build and Publish' marked build as failure 从从属服务器推出的内容超出了ECR插件的范围,还是我遗漏了什么?从属服务器中没有凭据,这就是问题所在。我修复了在按需从机中运行的每个管道

我正在用spotify的maven插件构建一个docker容器,然后尝试推送到ecr

这是在使用cloudbees插件登录后发生的

这就像詹金斯大师身上的符咒。 但在奴隶身上我得到:

no basic auth credentials

Build step 'Docker Build and Publish' marked build as failure

从从属服务器推出的内容超出了ECR插件的范围,还是我遗漏了什么?

从属服务器中没有凭据,这就是问题所在。我修复了在按需从机中运行的每个管道中注入此凭据的问题

 withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', accessKeyVariable: 'AWS_ACCESS_KEY_ID', credentialsId: 'AWS_EC2_key', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
                    sh "aws configure set aws_access_key_id ${AWS_ACCESS_KEY_ID}"
                    sh "aws configure set aws_secret_access_key ${AWS_SECRET_ACCESS_KEY}"
                    sh '$(aws ecr get-login --no-include-email --region eu-central-1)'


                sh "docker push ${your_ec2_repo}/${di_name}:image_name${newVersion}"

当然,您需要在从机中安装aws cli,您可能会遇到ECR插件中报告的错误:

该线程中的不同人员描述的症状略有不同,但共同的主题是docker未能使用ECR插件正确生成的auth详细信息

我发现这是因为ECR插件保存到一个docker配置,docker commons插件(处理docker API的实际工作)从另一个读取。Docker在早期版本中更改了配置格式和位置,导致了冲突

插件作者提供了一种解决方法,基本上只需首先对两个配置文件进行核处理:

node {
        //cleanup current user docker credentials
        sh 'rm  ~/.dockercfg || true'
        sh 'rm ~/.docker/config.json || true'

        //configure registry
        docker.withRegistry('https://ID.ecr.eu-west-1.amazonaws.com', 'ecr:eu-west-1:86c8f5ec-1ce1-4e94-80c2-18e23bbd724a') {

            //build image
            def customImage = docker.build("my-image:${env.BUILD_ID}")

            //push image
            customImage.push()
}
您可能想尝试纯粹作为调试步骤和快速修复(如果它起作用,您可以确信这个bug是您的问题)

我的永久解决方案是简单地使用合理的默认值手动创建新样式dockercfg,然后将环境变量设置为指向它

我在Dockerfile中这样做,它创建了Jenkins实例,如下所示:

RUN mkdir -p $JENKINS_HOME/.docker/ && \
    echo '{"auths":{}}' > $JENKINS_HOME/.docker/config.json
ENV DOCKER_CONFIG $JENKINS_HOME/.docker

这里的答案对我的管道不起作用。我发现这个解决方案有效,而且很干净:

withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', accessKeyVariable: 'AWS_ACCESS_KEY_ID', credentialsId: 'myCreds', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
    
    sh '''
    aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${REGISTRY}

    ..
    '''
}

此解决方案不需要aws cli v2。

谢谢您的回答,但我既不操作管道,也不想自己安装awscli和管理登录。我相信这可能会有所帮助?有任何评论反馈吗?