Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pull image from dockerhub in kubernetes?

I am planning to deploy an application in my kubernetes-clustering infra. I pushed image to dockerhub repo. How can I pull image from dockerhub?

like image 660
Snipper03 Avatar asked Feb 28 '18 15:02

Snipper03


People also ask

How do I pull an image from a private repository?

In order to pull images from your private repository, you'll need to login to Docker. If no registry URI is specified, Docker will assume you intend to use or log out from Docker Hub. Triton comes with several images built-in. You can view the available list with triton images .


2 Answers

One line command to create a Docker registry secret

kubectl create secret docker-registry regcred --docker-username=<your-name> --docker-password=<your-pword> --docker-email=<your-email> -n <your-namespace> 

Then you can use it in your deployment file under spec

spec:   containers:   - name: private-reg-container-name     image: <your-private-image>   imagePullSecrets:   - name: regcred 

More details: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/#create-a-secret-in-the-cluster-that-holds-your-authorization-token

like image 146
Bill Hegazy Avatar answered Sep 21 '22 07:09

Bill Hegazy


Kubernetes run docker pull pseudo/your-image:latest under the hood. image field in Kubernetes resources is simply the docker image to run.

spec:   containers:   - name: app     image: pseudo/your-image:latest [...] 

As the docker image name contains no specific docker registry url, the default is docker.io. Your image is in fact docker.io/pseudo/your-image:latest

If your image is hosted in a private docker hub repo, you need to specify an image pull secret in the spec field.

spec:   containers:   - name: app     image: pseudo/your-image:latest   imagePullSecrets:   - name: dockerhub-credential 

Here is the documentation to create the secret containing your docker hub login: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/

like image 34
Yann C. Avatar answered Sep 22 '22 07:09

Yann C.