Reputation: 5367
I'm trying to add an image to the Docker daemon running inside my Minikube, so it can be Pulled locally for Development purposes.
First I check the list of local installed Docker images
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
Check minikube config:
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)
Now I run the command to use Docker environment inside Minikube:
user@kubetest:~/workspace$ eval $(minikube docker-env)
Now create the Docker image:
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
Now check list of 'local' Docker images - it should NOT be here?
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 Into minikube and check list of Docker images - it should be here?
_ _ ( ) ( )
___ ___ (_) ___ (_)| |/') _ _ | |_ __
/' _ ` _ `\| |/' _ `\| || , < ( ) ( )| '_`\ /'__`\
| ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )( ___/
(_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____)
$ 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
$
Why doesn't the image get added to minikube's Docker after I've set the environment?
NOTE: I have also tried eval $(minikube -p minikube docker-env)
as recommended elsewhere
Upvotes: 0
Views: 69
Reputation: 159030
sudo
discards most environment variables, but it's not necessary here.
The only reason you generally need to sudo docker ...
is because access on the /var/run/docker.sock
file is restricted; and that's because you can very easily use it to root the host. If you've set the $DOCKER_HOST
environment variable, you're not using this socket file, and so you don't need sudo
.
If you really need to run docker build
as root for other reasons, sudo -E
will preserve environment variables.
Upvotes: 2