NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

Pull a local image to run a pod in Kubernetes
From <https://stackoverflow.com/questions/40144138/pull-a-local-image-to-run-a-pod-in-kubernetes/40150867#40150867>
让k8s从本地镜像仓库拉取镜像
From <https://0xffff.one/d/618>

1) Start a local registry container(registry 1已经过期)
• docker run -d -p 5000:5000 --restart=always --name registry registry:2
检查是否运行成功,运行后浏览器出现 {}
• http://localhost:5000/v2/

2) Do docker images to find out the REPOSITORY and TAG of your local image. Then create a new tag for your local image :
• docker tag <local-image-repository>:<local-image-tag> localhost:5000/<local-image-name>
• docker tag artifactory.ap.manulife.com/docker/sg/rsf-aks-client-gongping:1.0-SNAPSHOT localhost:5000/rsf-aks-client-gongping:1.0-SNAPSHOT

公司可能网络设置不让从本地库pull image,所以总会出现ImagePullBackOff或ImagePullErr,can't pull image等错误,但不妨碍从hub.docker.com中拉取。办法是先将image推送到hub.docker.com中自己的repository为beyondream。
docker tag artifactory.ap.manulife.com/docker/sg/rsf-aks-client-gongping:1.0-SNAPSHOT beyondream/rsf-aks-client-gongping:1.1-SNAPSHOT

docker push beyondream/rsf-aks-client-gongping:1.1-SNAPSHOT

kubectl create -f .deployment.yaml

kubectl port-forward dep-rsf-aks-client-gongping-b869f4cd-t8xjb 8080:8080
Forwarding from 127.0.0.1:8080 -> 8080


If TAG for your local image is <none>, you can simply do:
• docker tag <local-image-repository> localhost:5000/<local-image-name>

3) Push to local registry :
• docker push localhost:5000/<local-image-name>
docker push localhost:5000/rsf-aks-client-gongping:1.0-SNAPSHOT

This will automatically add the latest tag to localhost:5000/<local-image-name>. You can check again by doing docker images.

检查镜像是否推成功(先删除本地镜像,再从仓库拉取运行):
• docker rmi localhost:5000/rsf-aks-client-gongping:1.0-SNAPSHOT
• docker run --name rsf-aks-client-gongping -p 8080:8080 -i -t --rm localhost:5000/rsf-aks-client-gongping:1.0-SNAPSHOT

4) In your yaml file, set imagePullPolicy to IfNotPresent :
...
spec:
containers:
- name: <name>
image: localhost:5000/<local-image-name>
imagePullPolicy: IfNotPresent
...
That's it. Now your ImagePullError should be resolved.


k8s的配置文件中经常看到有imagePullPolicy属性,这个属性是描述镜像的拉取策略

Always 总是拉取镜像
IfNotPresent 本地有则使用本地镜像,不拉取
Never 只使用本地镜像,从不拉取,即使本地没有
如果省略imagePullPolicy 镜像tag为 :latest 策略为always ,否则 策略为 IfNotPresent

原文链接:https://blog.csdn.net/shenghuiping2001/article/details/103600053


存出和载入镜像
https://wiki.jikexueyuan.com/project/docker-technology-and-combat/save_load.html>
存出镜像
如果要导出镜像到本地文件,可以使用 docker save 命令。
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu 14.04 c4ff7513909d 5 weeks ago 225.4 MB
...
$sudo docker save -o ubuntu_14.04.tar ubuntu:14.04
载入镜像
可以使用 docker load 从导出的本地文件中再导入到本地镜像库,例如
$ sudo docker load --input ubuntu_14.04.tar

$ sudo docker load < ubuntu_14.04.tar
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.