How to use a local image as service in a docker-machine - docker

I want to use a locally build docker image in my docker-machine
I have a swarm cluster set up with docker-machine and like to use locally build docker image. after ssh into a one node with docker-machine ssh manager
I want to start a service with a locally build image such as
docker service create --name=database --publish=3306:3306 <localDataBaseImage>
How can this be achieved

You need to push the image to docker hub/ local docker registry and use that image while creating containers in docker machine.
if you have the image in docker hub, you need to perform docker login in the docker-machine
if you have the image in local registry, create docker-machine with insecure-registries option pointing to the url of your registry.

Related

Docker make local container available for other containers

I have two local Docker containers container_a and container_b.
When starting container_b, container_b calls docker pull container_a. However, this fails as container_a is a local container and not hosted on a Docker registry such as Docker Hub.
Is it possible to let container_b use the locally available containers when calling docker pull without changing container_b and without uploading container_a to a Docker registry?
Mount local docker.sock to your container_b that pulls the image.
docker run -v /var/run/docker.sock:/var/run/docker.sock ...

How to connect docker host inside Minikube

I want to deploy K8s artifacts to minikube which it's docker images are not available on Docker Hub. Images are build locally when I build my project.
When I build my project the images are build locally. But I can't deploy the K8s artifacts to minikube because the images are simply not available locally to docker host inside minikube.
Therefore I need a method to build my project inside minikube's docker host
You can use eval $(minikube docker-env) to connect to the docker daemon from minikube (in your current terminal). Afterwards you can use any docker command which will run against the docker daemon from minikube.
So you can use docker build ..., which will store the images in the registry from minikube.
e.g.
eval $(minikube docker-env)
docker build -t my-app-image .
Documentation can be found at the minkube doc

how to use local images in kubernetes using minikube

I have just started working on k8s and I am doing some stuff locally,
I have a image created using docker desktop. Now, I want this image to be used within my minikube's VM environment. I want to create a deployment using kubectl create deployment hello-minikube --image=my_local_image_name. Going through docs, and as per my understanding, it tells us how docker desktop can be used to interact with the minikube's in-built docker demon.
Following the instructions,
Running docker images gives me images within minikube's docker.
But, in my case I want the other way around.
How can I do that ?
Secondly, as a add-on how can I store images within minikube's VM's docker ?
Docker Desktop and Docker from Minikube are two separate Docker Engines. That is why they don't share the Docker image registry.
So you have the following options:
Use Kubernetes from Docker Desktop instead of Minikube (Docker Desktop comes with Kubernetes cluster built-in).
Build your Docker image with Docker Engine from Minikube (instead of Docker Desktop).
Use external Docker registry (you can use Docker Hub or set up your own registry)
Running docker images gives me images within minikube's docker.
When you have this behaviour in your shell, rebuild your docker image.
It will use Docker from Minikube and store your image into Minikube's Docker registry

Using BlueMix Container Registry service without local docker running

I am using Minikube to test everything I deploy in IBM Bluemix kubernetes service. I have my Macbook docker environment configured to use Minikube and I don't start standard basic Docker daemon/service in my MacBook. I just:
eval $(minikube docker-env)
It works great and I use same yaml files in Minikube than then I apply to Bluemix, as I use that Docker and Minikube image registry. Problem: when I try to login to BX CR to push an image from Minikube registry I get:
MacBook-Pro:Docker and Kubernetes icordoba$ bx cr login
Logging in to 'registry.ng.bluemix.net'...
FAILED
Failed to 'docker login' to 'registry.ng.bluemix.net' with error: Warning: failed to get default registry endpoint from daemon (Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?). Using system default: https://index.docker.io/v1/
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
.
It seems bx cr login command needs local docker host daemon running so I need to build image into Minkube registry, test in Minikube, shut it down, start Docker, build image again i docker registry, login to bx cr and push the image...
Can I make bx cr login command work with Minikube docker environment and not basic docker environment configured?
As mentioned in the comments the docker CLI is a pre-requirement for pushing to and pulling from the registry.
It should be possible to ssh into minikube using minikube ssh allowing you access to the docker daemon within minikube. You would then need to install the Bluemix cli and cr plugin. It should then be possible to push your images from there.
Alternatively you could install the IBM-Containers plugin found here. Then you can build your container in Bluemix and it will automatically push the image into the Container Registry for you to use with Kubernetes. This would allow you to build and push images without access to a docker daemon.
bx ic build -t registry.ng.bluemix.net/<namespace>/<image>:<tag> DOCKERFILE_PATH
(Adjust the registry region prefix based on which region you want your image to be pushed to)

Pulling image from local docker insecured Docker registry to Kubernetes

Cannot pull image from local docker insecured registry repository inside Minikube.
I'm running Docker-toolbox v1.12.2 using Linux VM (Upstart) installed on Oracle VirtualBox 5.1.6 under Windows 7.
I've created a docker image and push (tag and then push) it into a local insecured docker-registry v2 that running on 192.168.99.100:5000/image/name.
docker run -d -p 5000:5000 --restart=always --name registry registry:2
and inside the VM, on /var/lib/boot2docker/profile I've add to the EXTRA_ARGS the flag --insecure-registry 192.168.99.100:5000 .
docker push & docker pull from localhost:5000/image/name are working fine within Docker(VM).
_catalog is reachable from Postman :GET http:192.168.99.100:5000/v2/_catalog and I'm able to get the images inside the registry.
I'm starting my Minikube v0.15.0 VM with the command:
minikube start --insecure-registry=192.168.99.100:5000
I'm under company PROXY so I've added the proxy in the command line (CMD):
set HTTP/HTTPS_PROXY=my.company.proxy:8080 and set NO_PROXY={minikube ip}.
Then Kubernetes dashboard started to work for me.
Now for the real problem, when running the command:
kubectl run image-name --image=192.168.99.100:5000/image/name --port=9999
to pull image from my local docker registry into Kubernetes its saying
deployment "image-name" created
But inside Kubernetes > Deployments I'm getting the following error:
Failed to pull image "192.168.99.109:5000/image/name": image pull failed for 192.168.99.100:5000/image/name:latest, this may be because there are no credentials on this request. details: (Error response from daemon: Get https://192.168.99.100:5000/v1/_ping: Tunnel or SSL Forbidden)
Can anyone help here with that Tunnel or SSL Forbidden error, it's driving me crazy, and I've tried so many solutions to configure --insecrue-registery inside docker, inside Kubernetes or when running the dokcer-registry.
BTW why it's refering to v1/_ping? i'm using the docker registry v2.
Seems like minikube cannot see the same network that your registry is running. Can you try running minikube ssh then run your curl for the catalog?
Also, as an alternative, you could run eval(minikube docker-env) which then will set your local docker client to use the docker server inside minikube.
So for example if you built an image tagged with myimage/foo it would build and put that image on the minikube docker host, so when you deployed the image, it wouldn't need to be pulled.

Resources