Skip to content

Instantly share code, notes, and snippets.

@rkuzsma
Last active May 18, 2024 15:40
Show Gist options
  • Save rkuzsma/b9a0e342c56479f5e58d654b1341f01e to your computer and use it in GitHub Desktop.
Save rkuzsma/b9a0e342c56479f5e58d654b1341f01e to your computer and use it in GitHub Desktop.
Example Kubernetes yaml to pull a private DockerHub image
Step by step how to pull a private DockerHub hosted image in a Kubernetes YML.
export DOCKER_REGISTRY_SERVER=https://index.docker.io/v1/
export DOCKER_USER=Type your dockerhub username, same as when you `docker login`
export DOCKER_EMAIL=Type your dockerhub email, same as when you `docker login`
export DOCKER_PASSWORD=Type your dockerhub pw, same as when you `docker login`
kubectl create secret docker-registry myregistrykey \
--docker-server=$DOCKER_REGISTRY_SERVER \
--docker-username=$DOCKER_USER \
--docker-password=$DOCKER_PASSWORD \
--docker-email=$DOCKER_EMAIL
If your username on DockerHub is DOCKER_USER, and your private repo is called PRIVATE_REPO_NAME, and the image you want to pull is tagged "latest", create this dummy.yaml file:
apiVersion: v1
kind: Pod
metadata:
name: foo
spec:
containers:
- name: whatever
image: index.docker.io/DOCKER_USER/PRIVATE_REPO_NAME:latest
imagePullPolicy: Always
command: [ "echo", "SUCCESS" ]
imagePullSecrets:
- name: myregistrykey
Then run:
kubectl create -f dummy.yaml
@theobouwman
Copy link

Is this still up-to-date?

@marcboivin
Copy link

It is

@mvah
Copy link

mvah commented Mar 10, 2019

good

@pierredavidbelanger
Copy link

It works!

I did not need to use the --docker-email= param in the kubectl create secret command.

Also, I did not prefixed the image with index.docker.io/, only plain DOCKER_USER/PRIVATE_REPO_NAME:latest works for me.

Thank you

@AlejandroBudy
Copy link

it worked like a charm! 🥇

@shyaml
Copy link

shyaml commented Mar 6, 2020

i am using just a local docker with kubernetes/minikube installed on my desktop. how do i set the docker registry and configure for minikube please

@mudiasa
Copy link

mudiasa commented Mar 26, 2020

Thank you man! You've saved my day! :)

@Philip-Nunoo
Copy link

👍

@Macmee
Copy link

Macmee commented Jun 10, 2022

I think they may have changed something as this no longer works sadly.

@monty-wright
Copy link

I struggled getting this exact scenario to work for a while. [except on Windows] These steps finally got all the right pieces in the right places and it worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment