Using minikube as a “docker-machine” to avoid sharing a local-registry

How do I get a locally built docker image into minikube with the least amount of pain, and the greatest amount of speed?

If you’re developing with minikube, you’d frequently need to get docker images you build locally inside minikube so that your kubernetes deployments etc. work well.

TL;DR:

Run: eval $(minikube docker-env) and use docker to build images. Docker images will be built inside (and will hence be available inside) minikube.


In an earlier guide, https://blog.hasura.io/sharing-a-local-registry-for-minikube-37c7240d0615 I talked about how you can run a local registry on minikube and integrate your normal docker workflow with it.

Pros of running docker-registry inside minikube: Docker images are built outside minikube (on your local filesystem, or inside docker-machine)

Cons of running docker-registry inside minikube: You need to setup atleast one port-forward and keep it running, and 2 if you’re on a non-linux system


There is an alternative approach of getting your files inside minikube without having to run a local registry at all.

Instead of building images outside minikube and then getting them inside minikube:

docker build some-image          #this happens on your local docker
docker push minikube/some-image  #you push the image to minikube

you can:

docker build some-image         #this is happening inside minikube!

Before:

The docker build runs on the “local” docker daemon and the kubernetes “docker pull” on a different daemon.

After:

They can just be the same docker-daemon and we’ll save many kittens!

Point your docker client to run against the docker-daemon inside minikube:

Once you’ve created a minikube cluster with minikube start. This is a one-liner:

$> eval $(minikube docker-env)

And that’s it. Your local docker is now using the docker daemon inside minikube.

$> docker build -t my-image .   #Build a docker image locally
$> minikube ssh
$> docker images my-image       #You'll see the docker image here

Summary

Quick and dirty: eval $(minikube docker-env)

The longer way, safer if you’re re-creating minikube clusters often: https://blog.hasura.io/sharing-a-local-registry-for-minikube-37c7240d0615#47b3


Hasura is an open-source engine that gives you realtime GraphQL APIs on new or existing Postgres databases, with built-in support for stitching custom GraphQL APIs and triggering webhooks on database changes.


Tanmai Gopal

Tanmai Gopal

Tanmai is the co-founder of hasura.io. He is a StackOverflow powered fullstack developer and is passionate about making it easier to build things.

Read More