Docker镜像未从dockerhub.com注册表中获取最新信息 [英] Docker image not pulling latest from dockerhub.com registry

查看:88
本文介绍了Docker镜像未从dockerhub.com注册表中获取最新信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在实施CI/CD管道时,我使用docker,kubernetes和jenkins进行实施.而且我正在将生成的Docker映像推送到Dockerhub存储库.

当我提取文件时,它并没有从Dockerhub.com注册表中获取最新消息.因此,它没有在我的应用程序中显示更新的响应.我添加了testdeployment.yaml文件,如下所示.而且存储库凭据仅存储在Jenkinsfile中.

spec:
  containers:
   - name: test-kube-deployment-container
     image: "spacestudymilletech010/spacestudykubernetes:latest"
     imagePullPolicy: Always
     ports:
        - name: http
          containerPort: 8085
          protocol: TCP

Jenkinsfile

 sh 'docker build -f /var/lib/jenkins/workspace/jpipeline/pipeline/Dockerfile -t spacestudymilletech010/spacestudykubernetes:latest /var/lib/jenkins/workspace/jpipeline/pipeline'
 sh 'docker login --username=<my-username> --password=<my-password>' 
 sh 'docker push spacestudymilletech010/spacestudykubernetes:latest'

如何确定为什么不从Dockerhub.com获取最新映像?

解决方案

您似乎反复将:latest推入dockerhub?

如果是这样,那么这就是您遇到问题的原因.您可以从Jenkins工作中将最新消息推送到中心,但是如果运行部署容器的k8s节点已经在本地存储了名为latest的标签,那么它将使用它.

为了澄清-latest只是一个字符串,也可以是foobar. Docker不会拉出容器的最新版本实际上不是平均值.

这有两点:

  • 在k8s中使用latest几乎总是一个很糟糕的主意.
  • 多次推送同一标签始终是个坏主意,实际上许多回购协议都不允许您这样做.

关于完全使用latest.这是因为在我的工作场所,在我们使用k8s的早期,个人经验使我们在任何地方都使用了它.直到有一天我们发现我们的人偶服务器不再工作.在调查中,我们发现该节点已死亡,该吊舱在另一个节点上重新旋转,并拉出了另一个latest,这是一个新的主要发行版,破坏了事情.

这并不明显,因为kubectl describe pod显示的标记名称与以前相同,因此显然没有任何改变.

要添加注释中提到的要点: 您有ImagePullPolicy: 'Always',但是如果您正在执行kubectl apply -f mypod.yaml,并且标签名称相同,则k8s无法知道您实际上已经更改了图像

When I am implementing the CI/CD pipeline, I am using docker, kubernetes and jenkins for implementation. And I am pushing the resulting Docker image to Dockerhub repository.

When I am pulling it is not pulling the latest from the Dockerhub.com registry. So it's not showing the updated response in my application. I added the testdeployment.yaml file like the following. And repository credentials are storing in Jenkinsfile only.

spec:
  containers:
   - name: test-kube-deployment-container
     image: "spacestudymilletech010/spacestudykubernetes:latest"
     imagePullPolicy: Always
     ports:
        - name: http
          containerPort: 8085
          protocol: TCP

Jenkinsfile

 sh 'docker build -f /var/lib/jenkins/workspace/jpipeline/pipeline/Dockerfile -t spacestudymilletech010/spacestudykubernetes:latest /var/lib/jenkins/workspace/jpipeline/pipeline'
 sh 'docker login --username=<my-username> --password=<my-password>' 
 sh 'docker push spacestudymilletech010/spacestudykubernetes:latest'

How can I identify why it is not pulling latest image from the Dockerhub.com?

解决方案

It looks like you are repeatedly pushing :latest to dockerhub?

If so, then that's the reason for your issue. You push latest to the hub from your Jenkins job, but if the k8s node which runs the deployment pod already has a tag called latest stored locally, then that's what it will use.

To clarify - latest is just a string, it could equally well be foobar. It doesn't actually mean that docker will pull the most recent version of the container.

There are two takeaways from this:

  • It's almost always a very bad idea to use latest in k8s.
  • It is always a bad idea to push the same tag multiple times, in fact many repo's won't let you.

With regards to using latest at all. This comes from personal experience, at my place of work, in the early days of our k8s adoption, we used it everywhere. That is until we found one day that our puppet server wasn't working any more. On investigation we found that the node had died, the pod re-spun on a different node and a different latest was pulled which was a new major release, breaking things.

It was not obvious, because kubectl describe pod showed the same tag name as before so nothing, apparently, had changed.

To add an excellent point mentioned in the comments: You have ImagePullPolicy: 'Always', but if you're doing kubectl apply -f mypod.yaml, with the same tag name, k8s has no way of knowing you've actually changed the image

这篇关于Docker镜像未从dockerhub.com注册表中获取最新信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆