How to create docker images inside minikube registry

4/20/2020

I'm trying to use kubernetes locally. Thus I installed minikube. When I create deployment object, pods can't find the images within minikube docker registry and pods' show status as ErrImageNeverPull. To solve the problem I followed these steps:

  1. minikube start
  2. eval $(minikube docker-env)
  3. I changed ImagePullPolicy to Never in deployment.yaml file
  4. docker-compose build && docker-compose up -d

Even though I followed all these steps images for the project not being created within minikube registry. I have double checked it by running this command eval $(minikube docker-env -u) in order to switch back to the local docker registry. Images and Containers have been created within local docker registry.

My question is how can I create docker images within minikube docker registry?

-- Elshan Akberov
docker
kubernetes
microservices
minikube

2 Answers

4/20/2020

Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.

  • That's probably the reason why the eval didn't work, because the eval is made for docker binary, not docker-compose. Use a Dockerfile to run docker build and it should be registered directly to Minikube Image Registry.

from Minikube Documentation: Comparing 5 ways to push your image into a minikiube cluster, the best way to do it is as describe below:

My question is how can I create docker images within minikube docker registry?

  • You can run minikube ssh and you can build the images directly on the Minikube VM. The Docker environment is already set there:
$ minikube ssh
                         _             _            
            _         _ ( )           ( )           
  ___ ___  (_)  ___  (_)| |/')  _   _ | |_      __  
/' _ ` _ `\| |/' _ `\| || , <  ( ) ( )| '_`\  /'__`\
| ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )(  ___/
(_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____)


$ docker images
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
nginx                latest              e791337790a6        3 days ago          127MB
nginx                <none>              ed21b7a8aee9        2 weeks ago         127MB
ubuntu               latest              4e5021d210f6        4 weeks ago         64.2MB
  • Remember, you have to use the standard docker build to register the images into the registry. docker-compose is not baked inside Minikube VM

Let me know in the comments if you have any doubt.

-- willrof
Source: StackOverflow

4/21/2020

I have solved the problem by following these steps:

  1. Restarted minikube by executing minikube start
  2. I ran minikube -p minikube docker-env and it returned following:

    output of command

  3. I executed eval $(minikube -p minikube docker-env)

  4. Then I ran docker-compose commands.

Images and Containers was created within minikube docker registry.

To be honest I don't know why eval $(minikube docker-env) didn't do the job and the differences between eval $(minikube docker-env) and eval $(minikube -p minikube docker-env).

If you know the reason please let me know.

-- Elshan Akberov
Source: StackOverflow