As the handbook describes, you can reuse the Docker daemon from Minikube with eval $(minikube docker-env)
.
正如手册中所描述的,您可以使用val$(mini kube docker-env)重用Minikube中的Docker守护进程。
So to use an image without uploading it, you can follow these steps:
因此,如果要在不上传图片的情况下使用图片,可以按照以下步骤操作:
- Set the environment variables with
eval $(minikube docker-env)
- Build the image with the Docker daemon of Minikube (e.g.,
docker build -t my-image .
)
- Set the image in the pod specification like the build tag (e.g.,
my-image
)
- Set the
imagePullPolicy
to Never
, otherwise Kubernetes will try to download the image.
Important note: You have to run eval $(minikube docker-env)
on each terminal you want to use, since it only sets the environment variables for the current shell session.
重要提示:您必须在要使用的每个终端上运行val$(mini kube docker-env),因为它只为当前的外壳会话设置环境变量。
What worked for me, based on the solution by svenwltr:
根据svenwltr的解决方案,对我起作用的是:
# Start minikube
minikube start
# Set docker env
eval $(minikube docker-env) # Unix shells
minikube docker-env | Invoke-Expression # PowerShell
# Build image
docker build -t foo:0.0.1 .
# Run in Minikube
kubectl run hello-foo --image=foo:0.0.1 --image-pull-policy=Never
# Check that it's running
kubectl get pods
There is one easy and effective way to push your local Docker image directly to Minikube, which will save time from building the images in Minikube again.
有一种简单而有效的方法可以将您本地的Docker映像直接推送到Minikube,这将节省您再次在Minikube构建映像的时间。
minikube image load <image name>
(minikube cache add <image name>
—the old deprecated way, for reference)
(Minikube缓存添加<图像名称>-旧的废弃方式,供参考)
More details are here.
更多细节在这里。
All possible method to push images to Minikube are mention here: Pushing images
这里提到了所有可能的将图片推送到Minikube的方法:推送图片
Notes:
This answer isn’t limited to Minikube!
这个答案并不局限于小久部!
If wanting to create the registry on Minikube's Docker then run eval $(minikube docker-env)
first (to make docker
available on the host machine's terminal).
Otherwise, enter in the virtual machine via minikube ssh
, and then proceed with the following steps
如果想要在Minikube的Docker上创建注册表,则首先运行val$(mini kube docker-env)(以使docker在主机的终端上可用)。否则,请通过mini kube ssh进入虚拟机,然后继续执行以下步骤
depending on your operative system, Minikube will automatically mount your homepath onto the VM.
根据您的操作系统,Minikube会自动将您的HomePath装载到VM上。
as Eli stated, you'll need to add the local registry as insecure in order to use http (may not apply when using localhost, but it does apply if using the local hostname).
Don't use http in production. Make the effort for securing things up.
正如Eli所说,您需要将本地注册表添加为不安全才能使用http(使用本地主机时可能不适用,但如果使用本地主机名则适用)。在生产中不要使用http。尽最大努力把事情做好。
Use a local registry:
使用本地注册表:
docker run -d -p 5000:5000 --restart=always --name local-registry registry:2
Now tag your image properly:
现在,正确地标记您的图像:
docker tag ubuntu localhost:5000/ubuntu
Note that localhost should be changed to the DNS name of the machine running registry container.
请注意,本地主机应该更改为运行注册表容器的计算机的DNS名称。
Now push your image to the local registry:
现在将您的映像推送到本地注册表:
docker push localhost:5000/ubuntu
You should be able to pull it back:
你应该可以把它拉回来:
docker pull localhost:5000/ubuntu
Now change your YAML file to use the local registry.
现在更改您的YAML文件以使用本地注册表。
Think about mounting volumes at appropriate location, to persist the images on the registry.
考虑在适当的位置装入卷,以将映像持久保存在注册表中。
Adding to to Farhad's answer based on this answer,
除了法哈德基于这个答案的回答之外,
These are the steps to set up a local registry.
以下是设置本地注册表的步骤。
Set up in local machine
在本地计算机中设置
Set up the hostname in the local machine: edit /etc/hosts
to add this line:
在本地计算机中设置主机名:编辑/etc/hosts以添加以下行:
docker.local 127.0.0.1
Now start a local registry (remove -d
to run non-daemon mode):
现在启动本地注册表(删除-d以运行非守护程序模式):
docker run -d -p 5000:5000 --restart=always --name registry registry:2
Now tag your image properly:
现在,正确地标记您的图像:
docker tag ubuntu docker.local:5000/ubuntu
Now push your image to the local registry:
现在将您的映像推送到本地注册表:
docker push docker.local:5000/ubuntu
Verify that the image is pushed:
验证是否推送了该镜像:
curl -X GET http://docker.local:5000/v2/ubuntu/tags/list
Set up in Minikube
在Minkube设立
SSH into Minikube with: minukube ssh
使用SSH进入minkube:minukube ssh
Edit /etc/hosts to add this line:
编辑/ETC/Hosts以添加此行:
docker.local <your host machine's IP address>
Verify access:
验证访问权限:
curl -X GET http://docker.local:5000/v2/ubuntu/tags/list
Now if you try to pull, yo might get an http access error.
现在,如果您尝试拉,您可能会得到一个http访问错误。
Enable insecure access:
启用不安全访问:
If you are always planning to use Minikube with this local setup then create a Minikube instance to use the insecure registry by default (it won’t work on an existing cluster).
如果您总是计划在此本地设置中使用Minikube,那么创建一个Minikube实例以在默认情况下使用不安全的注册表(它不能在现有集群上工作)。
minikube start --insecure-registry="docker.local:5000"
Else follow the below steps:
否则,请执行以下步骤:
systemctl stop docker
Edit the Docker serice file: get path from systemctl status docker
编辑Docker服务文件:从系统ctl状态docker获取路径
It might be:
它可能是:
/etc/systemd/system/docker.service.d/10-machine.conf or
/usr/lib/systemd/system/docker.service
Append this text (replace 192.168.1.4 with your IP address)
追加此文本(将192.168.1.4替换为您的IP地址)
--insecure-registry docker.local:5000 --insecure-registry 192.168.1.4:5000
to this line
到这条线上
ExecStart=/usr/bin/docker daemon -H tcp://0.0.0.0:2376 -H unix:///var/run/docker.sock --tlsverify --tlscacert /etc/docker/ca.pem --tlscert /etc/docker/server.pem --tlskey /etc/docker/server-key.pem --label provider=virtualbox --insecure-registry 10.0.0.0/24
And:
以及:
systemctl daemon-reload
systemctl start docker
Try pulling:
试着拉:
docker pull docker.local:5000/ubuntu
Now change your YAML file to use the local registry.
现在更改您的YAML文件以使用本地注册表。
containers:
- name: ampl-django
image: dockerhub/ubuntu
to
至
containers:
- name: ampl-django
image: docker.local:5000/nymbleup
Don't use http in production. Make the effort for securing things up.
在生产中不要使用http。尽最大努力把事情做好。
Newer versions of Minikube allows you to load an image from the local Docker instance by running:
较新版本的Minikube允许您通过运行以下命令从本地Docker实例加载镜像:
minikube image rm image <imagename>:<version>
minikube image load <imagename>:<version> --daemon
The load command might show an error, but the image still gets loaded to your Minikube instance.
LOAD命令可能会显示错误,但图像仍会加载到您的Minikube实例中。
One thing to remember regarding Minikube is that Minikube's host is not the same as your local host, therefore, what I realized, that in order to use local images for testing with Minikube you must build your Docker image first locally or pull it locally and then add it using the command below into the Minikube context which is, nothing else as another Linux instance.
关于Minikube需要记住的一件事是,Minikube的主机与您的本地主机不同,因此,我意识到,为了使用本地映像进行Minikube测试,您必须首先在本地构建您的Docker映像,或者在本地拉入它,然后使用下面的命令将其添加到Minikube上下文中,也就是说,没有其他内容作为另一个Linux实例。
minikube cache add <image>:<tag>
Yet, don't forget to set the imagePullPolicy: Never
in your Kubernetes deployment YAML files, as it will ensure using locally added images instead of trying pull it remotely from the registry.
但是,不要忘记在您的Kubernetes部署YAML文件中设置ImagePullPolicy:Never,因为它将确保使用本地添加的映像,而不是尝试从注册表远程拉取它。
Note: minikube cache
will be deprecated in upcoming versions. Please switch to minikube image load
注意:Minikube缓存将在即将发布的版本中弃用。请切换到mini kube图像加载
One approach is to build the image locally and then do:
一种方法是在本地构建映像,然后执行以下操作:
docker save imageNameGoesHere | pv | (eval $(minikube docker-env) && docker load)
minikube docker-env
might not return the correct info running under a different user / sudo. Instead you can run sudo -u yourUsername minikube docker-env
.
Mini kube docker-env可能无法返回在不同用户/sudo下运行的正确信息。相反,您可以运行sudo-u YourUserName mini kube docker-env。
It should return something like:
它应该返回如下内容:
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/home/chris/.minikube/certs"
export DOCKER_API_VERSION="1.23"
# Run this command to configure your shell:
# eval $(minikube docker-env)
In addition to the accepted answer, you can also achieve what you originally wanted (creating a deployment using the run
command) with the following command:
除了接受的答案之外,您还可以使用以下命令实现您最初想要的结果(使用Run命令创建展开):
kubectl run hdfs --image=fluxcapacitor/hdfs:latest --port=8989 --generator=run-pod/v1
I found the information about the generator on the Kubernetes-dev forum:
我在Kubernetes-dev论坛上找到了关于生成器的信息:
If you're using kubectl run
, it generates a manifest for you that happens to have imagePullPolicy
set to Always
by default. You can use this command to get an imagePullPolicy
of IfNotPresent
, which will work for minikube
:
kubectl run --image=<container> --generator=run-pod/v1
Dan Lorenc
https://groups.google.com/forum/#!topic/kubernetes-dev/YfvWuFr_XOM
Https://groups.google.com/forum/#!topic/kubernetes-dev/YfvWuFr_XOM
If anyone is looking to come back to the local environment after setting the Minikube environment, use the following command.
如果任何人希望在设置Minikube环境后返回到本地环境,请使用以下命令。
eval $(docker-machine env -u)
A simpler method that answers the question "How can I use local docker images with Minikube?", is to save the image to a tar file and load it into Minikube:
更简单的方法是将图像保存到tar文件中,然后将其加载到Minikube中:
# Export the Docker image to a tar file
docker save --output my-image.tar the.full.path.to/the/docker/image:the-tag
# Set local environment variables so that docker commands go to the Docker in Minikube
eval $(minikube docker-env)
# Or if on Windows: @FOR /f "tokens=*" %i IN ('minikube docker-env') DO @%i
# Import the Docker image from the tar file into Minikube
docker load --input my-image.tar
# Cleanup - put Docker back to normal
eval $(minikube docker-env -u)
# Or if on Windows: @FOR /f "tokens=*" %i IN ('minikube docker-env -u') DO @%i
Then running the image involves a command like the following. Make sure to include the "--image-pull-policy=Never" parameter.
然后,运行映像涉及到如下命令。确保包含“--image-pull-policy=Never”参数。
kubectl run my-image --image=the.full.path.to/the/docker/image:the-tag --image-pull-policy=Never --port=80
For Windows users, the way I do it.
对于Windows用户,我做到了这一点。
I use the docker desktop to host my MiniKube image and use PowerShell as a console.
我使用docker桌面来托管我的MiniKube映像,并使用PowerShell作为控制台。
First I create my MiniKube cluster:
首先,我创建了我的MiniKube集群:
minikube start --bootstrapper=kubeadm --vm-driver=docker --profile "cluster1"
For instance, let's say I have a Dockerfile
contains:
例如,假设我有一个包含以下内容的Dockerfile:
FROM nginx
2 steps way, Build an image and Upload the image to minikube
两步法,构建镜像并将镜像上传到mini kube
docker build -t mynginximage .
minikube image load mynginximage
Or 1 step way, Build directly in MiniKube
或者一步一步,直接在MiniKube中构建
minikube image build -t mynginximage .
To run my image in MiniKube
在MiniKube中运行我的图像
kubectl run myweb --image=mynginximage --image-pull-policy=Never
or via mynginxpod.yaml
file:
或通过mynginxpod.yaml文件:
apiVersion: v1
kind: Pod
metadata:
name: myweb
spec:
containers:
- name: myweb
image: mynginximage
imagePullPolicy: Never
ports:
- containerPort: 80
And kubectl apply -f .\mynginxpod.yaml
和kubectl应用-f.\mynginxpod.yaml
Now to test it, run:
现在要测试它,运行:
kubectl get pods myweb
NAME READY STATUS RESTARTS AGE
myweb 1/1 Running 0 25s
To access it:
要访问它,请执行以下操作:
kubectl exec --stdin --tty myweb -- /bin/bash
To expose it:
要揭露它:
kubectl port-forward nginx 3333:80
From the Kubernetes documentation:
来自Kubernetes文档:
Updating images
正在更新图像
The default pull policy is IfNotPresent which causes the Kubelet to skip pulling an image if it already exists. If you would like to always force a pull, you can do one of the following:
- set the imagePullPolicy of the container to Always;
- use :latest as the tag for the image to use;
- enable the AlwaysPullImages admission controller.
Or read the other way: Using the :latest tag forces images to always be pulled. If you use the eval $(minikube docker-env)
as mentioned in other answers, then either don't use any tag, or assign a tag to your local image you can avoid Kubernetes trying to forcibly pull it.
或者以另一种方式阅读:使用:Latest标记强制始终拉出图像。如果你像在其他答案中提到的那样使用val$(mini kube docker-env),那么要么不使用任何标签,要么给你的本地镜像分配一个标签,这样你就可以避免Kubernetes试图强行拉出它。
One idea would be to save the Docker image locally and later load it into Minikube as follows:
一个想法是将Docker映像保存在本地,然后将其加载到Minikube中,如下所示:
Let’s say, for example, you already have puckel/docker-airflow image.
例如,假设您已经有了Puckel/docker-气流图像。
Save that image to local disk -
docker save puckel/docker-airflow > puckel_docker_airflow.tar
Now enter into the Minikube Docker environment -
eval $(minikube docker-env)
Load that locally-saved image -
docker load < puckel_docker_airflow.tar
It is that simple, and it works like a charm.
就是这么简单,它的效果就像一种护身符。
Use:
使用:
minikube addons enable registry -p minikube
Output:
产出:
💡 Registry addon on with docker uses 32769 please use that instead
of default 5000 <br>
📘 For more information see:
https://minikube.sigs.k8s.io/docs/drivers/docker
And:
以及:
docker tag ubuntu $(minikube ip -p minikube):32769/ubuntu
docker push $(minikube ip -p minikube):32769/ubuntu
Or
或
minikube addons enable registry
docker tag ubuntu $(minikube ip):32769/ubuntu
docker push $(minikube ip):32769/ubuntu
The above is good enough for development purposes. I am doing this on Arch Linux.
以上内容对于开发目的来说已经足够好了。我是在Arch Linux上这样做的。
There are two easy ways to load local images to Minikube.
有两种简单的方法可以将本地图像加载到Minikube。
Always make sure to set imagePullPolicy: Never in your deployment yaml.
始终确保在部署YAML中设置ImagePullPolicy:Never。
Eg:
例如:
spec:
containers:
- name: myapp
image: pz/demo
imagePullPolicy: Never
ports:
- containerPort: 8080
Luckily, there are two straightforward commands to help with this.
幸运的是,有两个简单的命令可以帮助您做到这一点。
- The first one is the image load command. You can load a Docker image from your local machine into the Minikube cluster with the following command.
General
minikube image load <IMAGE_NAME>
Mini kube镜像加载
Example
minikube image load pz/demo
Mini kube图像加载pz/demo
After loading the image to your Minikube cluster, you can restart your Pods of the above Deployment and notice that they are starting fine.
将映像加载到Minikube集群后,您可以重新启动上述部署的Pod,并注意到它们启动得很好。
- With the previous way, you always build the Docker image on your local machine and then move it to the Minikube container, which again takes a bit of time, even though not a lot.
Using the image build command of Minikube, we can build the image directly inside the Minikube container.
使用Minikube的映像构建命令,我们可以直接在Minikube容器中构建映像。
General
minikube image build -t <IMAGE_NAME> <PATH_TO_DOCKERFILE>
Mini kube镜像版本-t
Example
minikube image build -t pz/demo /New APP/Dockerfile
Mini kube镜像构建-t pz/demo/新应用程序/Dockerfile
Using the minikube image build command the image is instantly available to Minikkube and doesn't have to be explicitly loaded in a second step via the minikube image load command.
使用mini kube镜像构建命令,Minikube可以立即使用镜像,而不必在第二步中通过mini kube镜像加载命令显式地加载镜像。
Using one of both methods to get our application Docker image into Minikube and restart the Pods, we can recheck the logs of the Deployment:
使用这两种方法之一将我们的应用程序Docker镜像放入Minikube并重启Pods,我们可以重新检查部署的日志:
Further, to verify end to end that everything is working as expected, we can port forward our local port 8080 to the 8080 of the Deployment by using:
此外,要端到端验证一切是否按预期运行,我们可以使用以下命令将本地端口8080转发到部署的8080:
kubectl port-forward deployment/myapp 8080:8080
kubectl port-forward deployment/myapp 8080:8080
Rechecking the browser, we see that the locally built application runs fine on the Minikube cluster.
重新检查浏览器,我们看到本地构建的应用程序在Minikube集群上运行良好。
Ref: https://levelup.gitconnected.com/two-easy-ways-to-use-local-docker-images-in-minikube-cd4dcb1a5379
参考:https://levelup.gitconnected.com/two-easy-ways-to-use-local-docker-images-in-minikube-cd4dcb1a5379
There is now a Minikube Registry addon, and this is probably the easiest way. Here is how to use it: Registries
现在有了一个Minikube注册表插件,这可能是最简单的方法。以下是如何使用它:注册表
Note that I had DNS issues, and it might be a bug.
请注意,我遇到了DNS问题,这可能是一个错误。
You should know that docker in your local machine is separated from the docker in your minikube
cluster.
您应该知道,您本地计算机中的docker与您的mini kube集群中的docker是分开的。
So you should load/copy a Docker image from your local machine into the minikube cluster:
因此,您应该将本地机器上的Docker镜像加载/复制到mini kube集群:
minikube image load <IMAGE_NAME>
or alternatively when working with minikube
, you can build images directly inside it:
或者,在使用mini kube时,您可以直接在其内部构建映像:
#instead of:
docker image build -t <IMAGE_NAME> .
#do:
minikube image build -t <IMAGE_NAME> .
In addition of minikube image load <image name>
, check out the latest (Nov 2021 at the time of writing) release of Minikube.
除了Minikube图像加载<图像名称>之外,请查看最新发布的Minikube(撰写本文时是2021年11月)。
v1.24.0
V1.24.0
Add --no-kubernetes
flag to start minikube without Kubernetes
See PR 12848, for
That gives you:
这为您提供了:
mk start --no-kubernetes
minikube v1.24.0-beta.0 on Darwin 11.6 (arm64)
Automatically selected the docker driver
Starting minikube without Kubernetes minikube in cluster minikube
Pulling base image ...
Creating docker container (CPUs=2, Memory=1988MB) ...
Done! minikube is ready without Kubernetes!
Things to try without Kubernetes
- "
minikube ssh
" to SSH into minikube's node.
- "
minikube docker-env
" to build images by pointing to the docker inside minikube
- "
minikube image
" to build images without docker
To add to the previous answers, if you have a tarball image, you can simply load it to you local Docker set of images docker image load -i /path/image.tar
. Please remember to run it after eval $(minikube docker-env)
, since Minikube does not share images with the locally-installed Docker engine.
为了补充前面的答案,如果你有一个tarball镜像,你可以简单地将它加载到你的本地Docker镜像集中docker image load -i/path/image.tar。请记住在eval $(minikube docker-env)之后运行它,因为Minikube不与本地安装的Docker引擎共享图像。
Other answers suppose you use Minikube with a VM, so your local images are not accessible from the Minikube VM.
其他答案假设您将Minikube与一个VM一起使用,因此您的本地映像不能从Minikube VM访问。
In case if you use Minikube with --vm-driver=none
, you can easily reuse local images by setting image_pull_policy
to Never:
如果您将Minikube与--vm-drive=NONE一起使用,则可以通过将IMAGE_PULL_POLICY设置为NEVER来轻松重用本地映像:
kubectl run hello-foo --image=foo --image-pull-policy=Never
Or setting the imagePullPolicy
field for containers in corresponding .yaml
manifests.
或者为相应的.yaml清单中的容器设置ImagePullPolicy字段。
Steps to run local Docker images in Kubernetes:
在Kubernetes中运行本地Docker镜像的步骤:
eval $(minikube -p minikube docker-env)
In the artifact file, under the spec section → *containers.
Add:
imagePullPolicy: IfNotPresent
or
imagePullPolicy: Never
apiVersion: "v1"
kind: Pod
metadata:
name: web
labels:
name: web
app: demo
spec:
containers:
- name: web
image: web:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 5000
name: http
protocol: TCP
Then run kubectl create -f <filename>
For Minikube on Docker:
对于Docker上的Minikube:
Option 1: Using the Minikube registry
备选方案1:使用Minikube登记处
Check your Minikube ports
docker ps
You will see something like: 127.0.0.1:32769->5000/tcp
It means that your Minikube registry is on the 32769 port for external usage, but internally it's on the 5000 port.
Build your Docker image tagging it:
docker build -t 127.0.0.1:32769/hello .
Push the image to the Minikube registry:
docker push 127.0.0.1:32769/hello
Check if it's there:
curl http://localhost:32769/v2/_catalog
Build some deployment using the internal port:
kubectl create deployment hello --image=127.0.0.1:5000/hello
Your image is right now in the Minikube container. To see it, write:
eval $(minikube -p <PROFILE> docker-env)
docker images
Caveat: if using only one profile named "minikube" then "-p " section is redundant, but if using more then don't forget about it. Personally I delete the standard one (Minikube) not to make mistakes.
Option 2: Not using the registry
备选案文2:不使用登记处
Switch to Minikube container Docker:
eval $(minikube -p <PROFILE> docker-env)
Build your image:
docker build -t hello .
Create some deployment:
kubectl create deployment hello --image=hello
At the end, change the deployment ImagePullPolicy from Always to IfNotPresent:
kubectl edit deployment hello
Building off the earlier answer to use eval $(minikube docker-env)
in order to load up Minikube's Docker environment, for an easier toggle, add the following function to your shell rc file:
在前面的答案的基础上使用eval $(minikube docker-env)来加载Minikube的Docker环境,为了更容易切换,将以下函数添加到shell rc文件中:
dockube() {
if [[ $1 = 'which' ]]; then
if [[ $MINIKUBE_ACTIVE_DOCKERD = 'minikube' ]]; then
echo $MINIKUBE_ACTIVE_DOCKERD
else
echo 'system'
fi
return
fi
if [[ $MINIKUBE_ACTIVE_DOCKERD = 'minikube' ]]; then
eval $(minikube docker-env -u)
echo "now using system docker"
else
eval $(minikube -p minikube docker-env)
echo "now using minikube docker"
fi
}
dockube
without any argument will toggle between the system and Minikube Docker environment, and dockube which
will return which one is in use.
没有任何参数的dockube将在系统和Minikube Docker环境之间切换,而哪一个dockube将返回哪个正在使用中。
Short version
简短版本
Upload to minikube repository:
上传到mini kube存储库:
minikube image load imageName
Verify upload:
验证上载:
minikube image ls
Alternative solution:
Let's say I already have the Nginx
image locally.
假设我在本地已经有了nginx映像。
docker save -o nginx.tar nginx:1.19.0-alpine
minikube ssh
docker load -i /path/to/nginx.tar
Now, you can create a Kubernetes deployment using the local docker image.
现在,您可以使用本地docker镜像创建一个Kubernetes部署。
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: nginx
image: nginx:1.19.0-alpine
imagePullPolicy: IfNotPresent # Note: you can also user 'Never'
ports:
- containerPort: 80
Finally:
最后:
kubectl apply -f my-deployment.yml
What if you could just run Kubernetes within Docker's virtual machine? There's native support for this with the more recent versions of Docker Desktop... You just need to enable that support.
如果您只需在Docker的虚拟机中运行Kubernetes会怎么样?较新版本的Docker Desktop对此有本机支持...您只需启用该支持。
How I found this out:
我是如何发现的:
While reading the documentation for Helm, they give you a brief tutorial how to install Minikube.
That tutorial installs Minikube in a virtual machine that's different/separate from Docker.
在阅读Helm的文档时,他们会为您提供如何安装Minikube的简短教程。该教程将Minikube安装在与Docker不同/独立的虚拟机中。
So when it came time to install my Helm charts, I couldn't get Helm/Kubernetes to pull the images I had built using Docker. That's how I arrived here at this question.
因此,当需要安装我的Helm图表时,我无法让Helm/Kubernetes获取我使用Docker构建的图像。这就是我提出这个问题的原因。
So... if you can live with whatever version of Kubernetes comes with Docker Desktop, and you can live with it running in whatever VM Docker has, then maybe this solution is a bit easier than some of the others.
所以..。如果您可以接受Docker Desktop附带的Kubernetes的任何版本,并且可以在Docker拥有的任何VM上运行它,那么这个解决方案可能比其他一些解决方案更容易一些。
Disclaimer: I am not sure how switching between Windows/Linux containers would impact anything.
免责声明:我不确定在Windows/Linux容器之间切换会有什么影响。
- setup:
minikube docker-env
- again build the same Docker image (using
minikube docker-env
)
- change imagePullPolicy to Never in your deployment
Actually, your Minikube can't recognise your Docker daemon as it is ab independent service. You have to first set your Minikube-Docker environment use the below command to check:
事实上,你的Minikube无法识别你的Docker守护进程,因为它是一个独立的服务。您必须首先设置您的Minikube-Docker环境,使用以下命令进行检查:
"eval $(minikube docker-env)"
If you run the below command, it will show where your Minikube instance looks for Docker.
如果您运行下面的命令,它将显示您的Minikube实例查找Docker的位置。
cd ~
minikube docker-env
Output:
产出:
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.37.192:2376"
export DOCKER_CERT_PATH="/home/ubuntu/.minikube/certs"
export MINIKUBE_ACTIVE_DOCKERD="minikube"
**# To point your shell to minikube's docker-daemon, run:**
# eval $(minikube -p minikube docker-env)
You have to again build images once you set up the Minikube docker-env
. Else, it will fail.
一旦设置了mini kube docker-env,您必须再次构建映像。否则,它将失败。
Most of the answers are already great.
But one important thing I have faced is that if you are using BuildKit
大多数答案都已经很棒了。但我面临的一个重要问题是,如果您使用的是BuildKit
(DOCKER_BUILDKIT=1)
then the images created after executing the eval $(minkube docker-env)
will not go to minikube docker engine. Instead it will go to your docker engine on local.
则在执行val$(minkube docker-env)之后创建的图像将不会被转到mini kube docker引擎。取而代之的是,它将在本地连接到您的对接引擎。
So remove any of the references if you are using below
因此,如果您使用的是以下内容,请删除所有引用
-mount=type=cache,target=/root/.m2
You can reuse the Docker shell, with eval $(minikube docker-env)
. Alternatively, you can leverage docker save | docker load
across the shells.
您可以使用val$(mini kube docker-env)重用Docker外壳。或者,您可以跨壳利用停靠保存|停靠加载。
更多回答
Very important to remember to run eval $(minikube docker-env)
after closing the terminal you're working in BEFORE you try to rebuild images... just burned 6 hours fighting with an image that was not updating in minikube... looked like a package was not updating... really just not updating the image that minikube was referencing.
非常重要的一点是,在尝试重建镜像之前,请记住在关闭正在工作的终端后运行val$(mini kube docker-env)。刚刚在迷你立方与一张没有更新的图片战斗了6个小时…看起来像是一个包裹没有更新...真的只是没有更新Minikube引用的图像。
If u wanna back or exit env from minikube.. eval $(minikube docker-env -u)
如果你想返回或退出小型立方的环境..Eval$(mini kube docker-env-u)
How can I "Set the imagePullPolicy
to Never
" using kubectl
?
如何使用kubectl将ImagePullPolicy设置为Never?
Nowdays, you can also use minikube cache add imagename:tag
to push the image to the minikube - be sure to include the tag as well. Docs
现在,您还可以使用mini kube缓存添加ImageName:tag将图像推送到mini kube--请确保也包括该标签。多科
"minikube cache" will be deprecated in upcoming versions, please switch to "minikube image load"
- just got it from my terminal.
“mini kube缓存”将在即将到来的版本中被淘汰,请切换到“mini kube镜像加载”--刚刚从我的终端得到的。
You can find the yml version of the above command line (in regards to the imagePullPolicy) here : kubernetes.io/docs/concepts/containers/images
您可以在这里找到上面命令行的YML版本(与ImagePullPolicy相关):kubernetes.io/docs/Concept/Containers/Images
On Windows eval $(minikube docker-env) was not working for me. minikube docker-env | Invoke-Expression seems to work in PowerShell. In other terminals one needs to read the last line returned by minikube docker-env. For example, in IntelliJ (on Windows) it is @FOR /f "tokens=*" %i IN ('minikube -p minikube docker-env') DO @%i You have to do this in any new terminal/session always before building the docker image.
在Windows上,我不能使用val$(mini kube docker-env)。Mini kube docker-env|Invoke-Expression似乎可以在PowerShell中运行。在其他终端中,需要读取mini kube docker-env返回的最后一行。例如,在IntelliJ(在Windows上)中,它是@for/f“tokens=*”%i IN(‘mini kube-p mini kube docker-env’)do@%i您必须在任何新的终端/会话中执行此操作,始终在构建docker映像之前。
I am getting following error while doing eval $(minikube docker-env). "'none' driver does not support 'minikube docker-env' command" It is also logged on github it seems. github.com/kubernetes/minikube/issues/2443
我在执行val$(mini kube docker-env)时遇到以下错误。“‘None’驱动程序不支持‘mini kube docker-env’命令”它似乎也登录了GitHub。Githorb.com/Kubernetes/mini kube/Issues/2443
This answer should be higher in the list, it is the more up-to-date solution.
这个答案应该排在列表的前面,它是更新的解决方案。
I wonder why it's so slow. Sometimes it gets cancelled. Maybe not enough RAM
我想知道为什么它这么慢。有时会被取消。可能内存不足
There are sorting tabs at the top of the answers section, you probably selected one you're not used to, the best to choose is "Trending"
答案部分的顶部有排序选项卡,您可能选择了您不习惯的排序选项卡,最好的选择是“Trending”
Is there a way to force a pod to pick up the new image when I upload it into minikube repeatedly? Every time I upload a new image version with the same name/tag the pod keeps working on the old image until I delete the image explicitly in minikube and load it again.
当我反复上传到mini kube时,有没有办法强制Pod拾取新的图像?每次我上传具有相同名称/标签的新图像版本时,Pod都会继续处理旧图像,直到我在mini kube中显式删除图像并重新加载。
for anybody reading this anwer: it won't work without imagePullPolicy: Never
If you check out the logs you'll see that minikube is trying to pull the image even if it knows about it (minikube image ls
)
对于任何阅读本文的人来说:如果没有图像,它将无法工作PullPolicy:如果你查看日志,你永远不会看到mini kube正在试图拉出图像,即使它知道它(mini kube图像)
| Now change your yaml file to use the local registry. Are you able to explain this a little bit? I pushed to the local registry (cool trick) but I have the same problem that I can't get minikube to connect to it.
|现在更改您的YAML文件以使用本地注册表。你能稍微解释一下吗?我推送到本地注册表(很酷的把戏),但我有同样的问题,我无法连接到它的mini kube。
@ZachEstela change the image name in the yaml to <registryIP>:5000/ubuntu
@ZachEstela将yaml中的图像名称更改为:5000/ubuntu
@FarhadFarahi If I give my laptop to you, how would you find out? I just want to know it. I followed docker tutorial steps to get docker for windows running.
@FarhadFarahi如果我把笔记本电脑给你,你会怎么知道?我只想知道。我按照docker教程的步骤来运行docker for windows。
@FarhadFarahi: Please add to your answer that you'll need to add the local registry as insecure in order to use http: docs.docker.com/registry/insecure (may not apply when using localhost but does apply if using the local hostname).
@FarhadFarahi:请在您的回答中加上您需要将本地注册表添加为不安全才能使用http:docs.docker.com/Registry/insecure(使用本地主机时可能不适用,但使用本地主机名时确实适用)。
Failed to pull image "localhost:5000/src_interface:latest" according to my minikube dashboard, this doesn't seem to work. How would kubectl even access port 5000?
根据我的mini kube仪表板,无法拉取图像“localhost:5000/src_interface:Latest”,这似乎不起作用。Kubectl如何访问5000端口?
What is "Docker serice file"? Is it "Docker service file"? Or something else?
什么是Docker Serice文件?是“Docker服务文件”吗?还是别的什么?
this seems to be a great answer ... do you have any sources ?
这似乎是一个很好的答案..。你有什么消息来源吗?
How long does it take? Its running since 20 minutes for 645MB image
需要多长时间?它为645MB的图像运行了20分钟
While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value.
虽然这段代码可能会回答这个问题,但提供有关此代码为什么和/或如何回答问题的其他上下文会改善其长期价值。
The correct command is docker save imageNameGoesHere > pv | (eval $(minikube docker-env) && docker load)
正确的命令是docker save imageNameGoesHere > pv|(eval $(minikube docker-env)&& docker load)
docker save imageNameGoesHere | (eval $(minikube docker-env) && docker load)
worked for me
Docker保存ImageNameGoeshere|(val$(mini kube docker-env)&&docker Load)对我有效
Would be eval $(minikube docker-env -u) for minikube
对于mini kube,将是val$(mini kube docker-env-u)
Well explained, worked like a charm. I only had to call docker save
with sudo
, and then set sudo chmod 664 my-image.tar
to make it available for my current user.
解释得很好,像护身符一样起作用。我只需使用sudo调用docker save,然后设置sudo chmod 664 my-Image.tar以使其可用于我的当前用户。
You still need the accepted answer's tip of Set the imagePullPolicy to Never
. If your image is tagged with an address e.g. us.icr.io/mydiv/my-service:v0.0.1
then a deploy will try to remote pull this image. Since you've already manually copied the image, you need to suppress k8s from pulling the image from an address (container registry) it can't access.
您仍然需要接受答案的提示,即将ImagePullPolicy设置为Never。如果您的映像使用地址标记,例如us.icr.io/mydiv/my-service:v0.0.1,则部署人员将尝试远程获取此映像。由于您已经手动复制了镜像,因此需要禁止K8从它无法访问的地址(容器注册表)拉取镜像。
@colm.anseo The steps above worked for me but I had to replace the latest
tag in the image with a specific version and select this version in the create deploy command. The imagePullPolicy
was automatically set to IfNotPresent
and the image was loaded correctly without further changes.
@colm.anseo以上步骤对我有效,但我必须将映像中的最新标记替换为特定版本,并在Create Deploy命令中选择该版本。ImagePullPolicy被自动设置为IfNotPresent,并且图像被正确加载,没有进一步的更改。
How do u refer to the image in the k8s specs? By localhost:32769/ubuntu
or with the minikube ip or the registry dns name?
你如何指代K8规格中的形象?使用本地主机:32769/ubuntu,还是使用mini kube IP或注册表dns名称?
The link may or may not be half-broken (it redirects).
链接可能是半断的,也可能不是(它重定向的)。
Error: unknown command "build" for "minikube"
; what minikube version are you talking about?
错误:“mini kube”的命令“BUILD”未知;您说的是哪个mini kube版本?
@Kamafeather minikube version: v1.28.0 commit: 986b1ebd987211ed16f8cc10aed7d2c42fc8392f
you can install it from here
@Kamafeather mini kube版本:v1.28.0 Commit:986b1ebd987211ed16f8cc10aed7d2c42fc8392f您可以从这里安装
Oh, we are constrained to an earlier version at the moment, but thank you for the update I'll check it out!
哦,我们目前只能使用较早的版本,但感谢您的更新,我会查看的!
I think I also had to set the imagePullPolicies to IfNotPresent as well
我想我还必须将ImagePullPolures设置为IfNotPresent
The first link is (effectively) broken (it redirects to a generic page).
第一个链接(实际上)断开了(它重定向到一个通用页面)。
我是一名优秀的程序员,十分优秀!