在minikube上使用本地docker镜像

您使用Minikube,并且要运行在本地创建的开发映像。 这似乎很棘手,因为Minikube需要从注册表中下载图像,但是图像正在上载到本地注册表中。

无论如何,您仍然可以在Minikube中使用本地图像,因此让我们开始吧。

在运行任何容器之前,请先发布。

 > eval $(minikube docker- env ) 

实际上,这会将Minikube的docker主机重用于当前的bash会话。

你自己看。

 > minikube docker- env  export DOCKER_TLS_VERIFY= "1"  export DOCKER_HOST= "tcp://192.168.99.101:2376"  export DOCKER_CERT_PATH= "/Users/gkatzioura/.minikube/certs"  # Run this command to configure your shell:  # eval $(minikube docker-env) 

然后旋转nginx图像。 大多数命令都来自教程。

 >docker run -d -p 8080:80 --name my-nginx nginx  >docker ps --filter name=my-nginx  CONTAINER ID       IMAGE              COMMAND                 CREATED            STATUS             PORTS                 NAMES  128ce006ecae       nginx "nginx -g 'daemon of…" 128ce006ecae       nginx "nginx -g 'daemon of…" 13 seconds ago     Up 12 seconds      0.0.0.0:8080->80 /tcp my-nginx 

现在,让我们从正在运行的容器中创建一个图像。

 docker commit 128ce006ecae dockerimage:version1 

然后,让我们在minikube上运行自定义图像。

 kubectl create deployment test -image --image=dockerimage:version1 

让我们也公开一下服务

 kubectl expose deployment test -image -- type =LoadBalancer --port=80 

让我们进入一个新的水平,尝试获取我们的服务

 > kubectl exec -it podwithbinbash /bin/bash  bash -4.4 # wget test-image  Connecting to test -image (10.101.70.7:80)  index.html          100% |***********************************************************************************************************|  612 0:00:00 ETA  bash -4.4 # cat index.html  <!DOCTYPE html>  <html>  < head >  <title>Welcome to nginx!< /title >  <style> 
     body { 
         width: 35em; 
         margin: 0 auto; 
         font-family: Tahoma, Verdana, Arial, sans-serif; 
     }  < /style >  < /head >  <body>  <h1>Welcome to nginx!< /h1 >  <p>If you see this page, the nginx web server is successfully installed and  working. Further configuration is required.< working. Further configuration is required.< /p >  <p>For online documentation and support please refer to  <a href= >nginx.org< " http://nginx.org/ " >nginx.org< /a >.<br/>  Commercial support is available at  <a href= " http://nginx.com/ " >nginx.com< /a >.< /p >  <p><em>Thank you for using nginx.< /em >< /p >  < /body >  < /html > 

请特别注意,以上内容在您执行命令的终端上有效

 eval $(minikube docker- env ) 

如果您愿意,可以只设置bash_profile以便在每个终端上都可以,但这取决于您。
最终,这是在Minikube上使用本地图像的快速方法之一,并且很可能还有其他可用的方法。

翻译自: https://www.javacodegeeks.com/2020/03/use-local-docker-image-on-minikube.html