How do you make docker images build locally available to microk8s docker daemon?
Cannot find any documentation about that.
microk8s docker registry is only in --edge and that is unstable, I am running --beta version
Hi @safderali5 ,
I guess you are not interested in using a public repository to upload your images so I will skip this approach.
If you are on microk8s --beta at the moment you have to first build the image and get it into the docker daemon microk8s uses. This is done like this:
# Lets get a Docker file first
wget https://raw.githubusercontent.com/nginxinc/docker-nginx/ddbbbdf9c410d105f82aa1b4dbf05c0021c84fd6/mainline/stretch/Dockerfile
# And build it
/snap/microk8s/current/usr/bin/docker -H unix:///var/snap/microk8s/current/docker.sock build -t kjackal/nginx:testlocal .
Here I am using the docker client shipped with microk8s (/snap/microk8s/current/usr/bin/docker). Any client is fine as long as you point it to the socket where microk8s is listening on: -H unix:///var/snap/microk8s/current/docker.sock. With -t you can set a tag to your image so you can reference it later.
After building the image you can start a deployment but you have to make sure you do not try to pull a new image from DockerHub:
microk8s.kubectl run localnginx --image=kjackal/nginx:testlocal --image-pull-policy='Never'
In the --edge channel along with the private registry we also introduced an easier way to access the docker client. You can now build a new image with:
microk8s.docker build -t kjackal/nginx:testlocal .
If you want to use the local registry you can do this:
microk8s.enable registry
microk8s.docker build -t localhost:32000/nginx:testlocal .
microk8s.docker push localhost:32000/nginx:testlocal
microk8s.kubectl run localregnginx --image=localhost:32000/nginx:testlocal
Thanks
Thanks a lot for help, this worked. hope to see microk8s.docker in --beta version soon.
Most helpful comment
Hi @safderali5 ,
I guess you are not interested in using a public repository to upload your images so I will skip this approach.
If you are on microk8s --beta at the moment you have to first build the image and get it into the docker daemon microk8s uses. This is done like this:
Here I am using the docker client shipped with microk8s (
/snap/microk8s/current/usr/bin/docker). Any client is fine as long as you point it to the socket where microk8s is listening on:-H unix:///var/snap/microk8s/current/docker.sock. With-tyou can set a tag to your image so you can reference it later.After building the image you can start a deployment but you have to make sure you do not try to pull a new image from DockerHub:
In the --edge channel along with the private registry we also introduced an easier way to access the docker client. You can now build a new image with:
If you want to use the local registry you can do this:
Thanks