我有几个docker映像,我想使用minikube。我不想先上传然后再下载相同的图像,而不是直接使用本地图像。我怎么做呢?

我尝试过的东西: 1. 我试着运行这些命令(分别删除minikube的实例并重新开始)

kubectl run hdfs --image=fluxcapacitor/hdfs:latest --port=8989
kubectl run hdfs --image=fluxcapacitor/hdfs:latest --port=8989 imagePullPolicy=Never

输出:

NAME                    READY     STATUS              RESTARTS   AGE
hdfs-2425930030-q0sdl   0/1       ContainerCreating   0          10m

它只是停留在某个状态,但从未达到就绪状态。

2. 我试着创建一个注册表,然后将图像放入其中,但这也不起作用。我可能做错了,但我找不到正确的说明来做这个任务。

请提供在本地kubernetes实例中使用本地docker映像的说明。 操作系统:ubuntu 16.04 Docker: Docker版本1.13.1,build 092cba3 Kubernetes:

Client Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.3", GitCommit:"029c3a408176b55c30846f0faedf56aae5992e9b", GitTreeState:"clean", BuildDate:"2017-02-15T06:40:50Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.2", GitCommit:"08e099554f3c31f6e6f07b448ab3ed78d0520507", GitTreeState:"clean", BuildDate:"1970-01-01T00:00:00Z", GoVersion:"go1.7.1", Compiler:"gc", Platform:"linux/amd64"}

如果有人能帮我找到一个解决方案,使用docker-compose来做到这一点,那就太棒了。

编辑:

在eval $(minikube docker-env)中加载的图像:

REPOSITORY                                            TAG                 IMAGE ID            CREATED             SIZE
fluxcapacitor/jupyterhub                              latest              e5175fb26522        4 weeks ago         9.59 GB
fluxcapacitor/zeppelin                                latest              fe4bc823e57d        4 weeks ago         4.12 GB
fluxcapacitor/prediction-pmml                         latest              cae5b2d9835b        4 weeks ago         973 MB
fluxcapacitor/scheduler-airflow                       latest              95adfd56f656        4 weeks ago         8.89 GB
fluxcapacitor/loadtest                                latest              6a777ab6167c        5 weeks ago         899 MB
fluxcapacitor/hdfs                                    latest              00fa0ed0064b        6 weeks ago         1.16 GB
fluxcapacitor/sql-mysql                               latest              804137671a8c        7 weeks ago         679 MB
fluxcapacitor/metastore-1.2.1                         latest              ea7ce8c5048f        7 weeks ago         1.35 GB
fluxcapacitor/cassandra                               latest              3cb5ff117283        7 weeks ago         953 MB
fluxcapacitor/apachespark-worker-2.0.1                latest              14ee3e4e337c        7 weeks ago         3.74 GB
fluxcapacitor/apachespark-master-2.0.1                latest              fe60b42d54e5        7 weeks ago         3.72 GB
fluxcapacitor/package-java-openjdk-1.8                latest              1db08965289d        7 weeks ago         841 MB
gcr.io/google_containers/kubernetes-dashboard-amd64   v1.5.1              1180413103fd        7 weeks ago         104 MB
fluxcapacitor/stream-kafka-0.10                       latest              f67750239f4d        2 months ago        1.14 GB
fluxcapacitor/pipeline                                latest              f6afd6c5745b        2 months ago        11.2 GB
gcr.io/google-containers/kube-addon-manager           v6.1                59e1315aa5ff        3 months ago        59.4 MB
gcr.io/google_containers/kubedns-amd64                1.9                 26cf1ed9b144        3 months ago        47 MB
gcr.io/google_containers/kube-dnsmasq-amd64           1.4                 3ec65756a89b        5 months ago        5.13 MB
gcr.io/google_containers/exechealthz-amd64            1.2                 93a43bfb39bf        5 months ago        8.37 MB
gcr.io/google_containers/pause-amd64           

当前回答

大多数答案已经很棒了。 但我面临的一个重要问题是,如果你使用BuildKit

(DOCKER_BUILDKIT = 1)

然后,执行eval $(minkube docker-env)后创建的映像将不会进入minikube docker引擎。相反,它会到本地的docker引擎。

因此,如果您正在使用下面的任何引用

-mount = =缓存类型,target = / root /平方米。

其他回答

回答最初的问题“如何在Minikube中使用本地docker映像?”的一个更简单的方法是将映像保存到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

然后运行映像需要执行如下命令。确保包含"——image-pull-policy=Never"参数。

kubectl run my-image --image=the.full.path.to/the/docker/image:the-tag --image-pull-policy=Never --port=80

新版本的minikube允许您通过运行本地docker实例加载映像

 minikube image rm image <imagename>:<version>  
 minikube image load <imagename>:<version> --daemon

load命令可能会显示错误,但图像仍然会加载到minikube实例中

注:

This Answer isnt 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 depending on your operative system, minikube will automatically mount your homepath onto the 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 does apply if using the local hostname) Don't use http in production, make the effort for securing things up.


使用本地注册表:

docker run -d -p 5000:5000 --restart=always --name local-registry registry:2

现在正确地标记你的图像:

docker tag ubuntu localhost:5000/ubuntu

注意,localhost应该更改为运行注册表容器的机器的dns名称。

现在将您的映像推到本地注册表:

docker push localhost:5000/ubuntu

你应该可以把它拉回来:

docker pull localhost:5000/ubuntu

现在更改yaml文件以使用本地注册表。

考虑在适当的位置挂载卷,以便在注册表上持久化映像。

Docker上的minikube:

选项1:使用minikube注册表

检查你的minikube端口 码头工人ps

您将看到如下内容:127.0.0.1:32769->5000/tcp 这意味着您的minikube注册表对外使用的是32769端口,但对内使用的是5000端口。

构建你的docker图像标记它: Docker build -t 127.0.0.1:32769/hello。 将映像推到minikube注册表: Docker push 127.0.0.1:32769/hello 检查是否有: curl http://localhost: 32769 / v2 / _catalog 使用内部端口构建一些部署: Kubectl创建部署hello——image=127.0.0.1:5000/hello

你的图像现在在minikube容器中,要看到它写:

eval $(minikube -p <PROFILE> docker-env)
docker images

注意:如果只使用一个名为“minikube”的配置文件,那么“-p”部分是多余的,但如果使用更多则不要忘记它;就我个人而言,我删除了标准的(minikube),以免出错。

选项2:不使用注册表

切换到minikube容器Docker: $(minikube -p <配置> docker-env) 塑造你的形象: Docker build -t hello。 创建一些部署: Kubectl创建部署hello——image=hello

最后,将部署ImagePullPolicy从Always更改为IfNotPresent:

Kubectl编辑部署你好

在kubernetes中运行本地docker映像的步骤 1. Eval $(minikube -p minikube docker-env) 2. 在工件文件中,在规范部分->容器添加 imagePullPolicy: IfNotPresent或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

3.然后执行kubectl create -f <filename>