我正在尝试向Minikube中运行的Docker守护进程添加映像,因此可以出于开发目的将其拉到本地。
首先,我检查本地安装的Docker映像的列表
user@kubetest:~/workspace$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat 9.0 d5eef28cf41d 2 days ago 647MB
tomcat latest d5eef28cf41d 2 days ago 647MB
node slim 05f62d57259e 6 days ago 167MB
hello-world latest bf756fb1ae65 8 months ago 13.3kB
tomcat 8.0 ef6a7c98d192 24 months ago 356MB
检查minikube配置:
user@kubetest:~/workspace/local-minikube-docker$ minikube docker-env
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/home/user/.minikube/certs"
export DOCKER_API_VERSION="1.35"
# Run this command to configure your shell:
# eval $(minikube docker-env)
现在,我运行命令在Minikube中使用Docker环境:
user@kubetest:~/workspace$ eval $(minikube docker-env)
现在创建Docker映像:
user@kubetest:~/workspace$ cd local-minikube-docker/
user@kubetest:~/workspace/local-minikube-docker$ sudo docker build -t nodejs-server .
Sending build context to Docker daemon 69.12kB
Step 1/5 : FROM node:slim
---> 05f62d57259e
Step 2/5 : WORKDIR /usr/home
---> Running in 2d9e3d363188
Removing intermediate container 2d9e3d363188
---> 4c862acc9863
Step 3/5 : COPY index.js .
---> 2368cfc6ca5b
Step 4/5 : EXPOSE 3000
---> Running in 61e1081d2f21
Removing intermediate container 61e1081d2f21
---> f99db8ab886d
Step 5/5 : CMD ["node", "index.js"]
---> Running in b1f3de55de63
Removing intermediate container b1f3de55de63
---> 2ea9d8cf073a
Successfully built 2ea9d8cf073a
Successfully tagged nodejs-server:latest
现在检查“本地” Docker映像的列表-它不应该在这里吗?
user@kubetest:~/workspace/local-minikube-docker$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nodejs-server latest 2ea9d8cf073a 5 seconds ago 167MB
tomcat 9.0 d5eef28cf41d 2 days ago 647MB
tomcat latest d5eef28cf41d 2 days ago 647MB
node slim 05f62d57259e 6 days ago 167MB
hello-world latest bf756fb1ae65 8 months ago 13.3kB
tomcat 8.0 ef6a7c98d192 24 months ago 356MB
SSH进入minikube并检查Docker映像列表-应该在这里吗?
_ _ ( ) ( )
___ ___ (_) ___ (_)| |/') _ _ | |_ __
/' _ ` _ `\| |/' _ `\| || , < ( ) ( )| '_`\ /'__`\
| ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )( ___/
(_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____)
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
kubernetesui/dashboard v2.0.0-beta3 6feddba9df74 13 months ago 75.3MB
kubernetesui/metrics-scraper v1.0.1 709901356c11 13 months ago 40.1MB
k8s.gcr.io/kube-proxy-amd64 v1.10.0 bfc21aadc7d3 2 years ago 97MB
k8s.gcr.io/kube-scheduler-amd64 v1.10.0 704ba848e69a 2 years ago 50.4MB
k8s.gcr.io/kube-controller-manager-amd64 v1.10.0 ad86dbed1555 2 years ago 148MB
k8s.gcr.io/kube-apiserver-amd64 v1.10.0 af20925d51a3 2 years ago 225MB
k8s.gcr.io/etcd-amd64 3.1.12 52920ad46f5b 2 years ago 193MB
k8s.gcr.io/kube-addon-manager v8.6 9c16409588eb 2 years ago 78.4MB
k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64 1.14.8 c2ce1ffb51ed 2 years ago 41MB
k8s.gcr.io/k8s-dns-sidecar-amd64 1.14.8 6f7f2dc7fab5 2 years ago 42.2MB
k8s.gcr.io/k8s-dns-kube-dns-amd64 1.14.8 80cc5ea4b547 2 years ago 50.5MB
k8s.gcr.io/pause-amd64 3.1 da86e6ba6ca1 2 years ago 742kB
k8s.gcr.io/kubernetes-dashboard-amd64 v1.8.1 e94d2f21bc0c 2 years ago 121MB
gcr.io/k8s-minikube/storage-provisioner v1.8.1 4689081edb10 2 years ago 80.8MB
$
设置环境后,为什么映像没有添加到minikube的Docker中?
注意:我也尝试过在其他地方推荐的eval $(minikube -p minikube docker-env)
答案 0 :(得分:2)
sudo
会丢弃大多数环境变量,但这在这里是不必要的。
您通常需要sudo docker ...
的唯一原因是因为/var/run/docker.sock
文件的访问受到限制;那是因为您可以很容易地使用它来根主机。如果设置了$DOCKER_HOST
环境变量,则说明您没有使用此套接字文件,因此不需要sudo
。
如果出于其他原因确实需要以root用户身份运行docker build
,则sudo -E
将保留环境变量。