My os is windows 10 pro and I develop with spring boot. First I build docker image with below Dockerfile.
FROM openjdk:11-jdk
ADD target/Spring-Blog-Jpa-0.0.1-SNAPSHOT.jar blog-app.jar
EXPOSE 8080
ENTRYPOINT ["java","-Dfile.encoding=UTF8","-jar","blog-app.jar"]
The docker image is built successfully with the docker command.
> docker image build -t blog-app:latest .
And I pull mysql:latest image from docker repository. And mysql pulling is also successful.
> docker image pull mysql:latest .
I try to generate kubernetes pod with those docker images. In case of mysql:latest image, mysql pod is generated without errors. But when generating the blog-app pod, the blog-app:latest image can not be pulled and error message is thrown. Below is the configuration yaml file.
apiVersion: apps/v1
kind: Pod
metadata:
name: blog-system
spec:
containers:
- name: blog-app
image: blog-app:latest
args: ["-t", "-i"]
I have no idea why the locally built image can not be pulled when generating pod. Is there any process to push local docker repository? How can the locally built docker images can be pulled on Kuberetes?
You can reuse the Docker daemon from Minikube. Here are the commands on Powershell.
PS C:\minikube> minikube docker-env
PS C:\minikube> minikube docker-env | Invoke-Expression
docker image build -t blog-app:latest
Set the image in the pod spec like the build tag
Set the imagePullPolicy to Never, otherwise Kubernetes will try to download the image.
apiVersion: apps/v1
kind: Pod
metadata:
name: blog-system
spec:
containers:
- name: blog-app
image: blog-app:latest
imagePullPolicy: Never
args: ["-t", "-i"]
Also check this guide
This is a confusing aspect of Docker. Essentially Kubernetes is attempting to pull the image from a container registry and, (generally) until an image has been pushed to a registry, it can't be pulled.
When you docker [push|pull] ...
you're interacting with a (remote) container registry. By default (if your don't specify it), you're interacting with DockerHub and may assume that images (unless otherwise tagged) are prefixed by DockerHub's https://docker.io
. If you use, e.g. Google Container Registry, you'll more frequently use its host prefixes e.g. https://gcr.io
.
When you build a container on your host, until you docker push ...
the image, it is not in a registry.
When you reference an image in a Kubernetes spec|config, Kubernetes expects to pull the image from a registry. In your case, blob-app
is not in a registry and so this fails.
You can run a local registry to address this. One way you may do this is using Minikube per @arghya-sadhu answer. But you may also run a Docker image of Docker's own implementation of its Registry spec, see registry.
Or you can push your images to a publicly accessible registry, e.g. DockerHub, Google Container Registry, Quay and then reference the image from the registry as you've done with mysql
. DockerHub has a free tier that is very commonly used and permits both public and (limited number of) private repositories.