Search This Blog

Saturday, March 31, 2018

Host private docker registry and connect to it ( Windows version)

If you don’t want to use dockerhub you can host your own private registry.

Get a registry image from docker hub and host it in a container as shown below.

image

$docker pull registry // also works from toolbelt

I used kitematic, you can dirctly pull from command line also, make sure you map port 5000,

where the docker registry api listens for calls.

so my registry now listening on

image


Lets connect to it and see the content.


Use curl to fire api call to registry endpoint


$ curl -v -X GET http://192.168.99.102:32768/v2/_catalog
Note: Unnecessary use of -X or --request, GET is already inferred.
* timeout on name lookup is not supported
*   Trying 192.168.99.102...
* Connected to 192.168.99.102 (192.168.99.102) port 32768 (#0)
> GET /v2/_catalog HTTP/1.1
> Host: 192.168.99.102:32768
> User-Agent: curl/7.46.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
< Docker-Distribution-Api-Version: registry/2.0
< X-Content-Type-Options: nosniff
< Date: Fri, 30 Mar 2018 14:04:22 GMT
< Content-Length: 20
<
{"repositories":[]}
* Connection #0 to host 192.168.99.102 left intact


I used docker tool belt, i was on windows, it has curl on it.


So i could connect but there are no repositories currently.

Tag the image to puch to local repository

So the way to push a docker image locally to another private registry is by

naming it in such a way that the name has the url port and the image information.

so lets say we have hello-world image in > docker images

To pull it form dockerhub we do

docker run hello-world , it brings the image and run it and saves an image locally.

To push this hello-world image to our private repository , we will tag it like this.

> docker tag hello-world 192.168.99.102:32768/hello-world

Now it will automatically push it to the url  port and the image name specified, this is kind of a

trick to push images from local space to a private registry.


=======================


Lets try to push the image

> docker push 192.168.99.102:32768/hello-world

It ended up with error

 http: server gave HTTP response to HTTPS client

Multiple ways to solve this

If you natively on docker for windows, you can directly specify in preferences.

==============================

If you are using docker on unix, you can try to ssh into the minishift vm and add the daemon.json file in

the /etc/docker/daemon.json and sudo service docker restart(Should work)


// daemon.json file content

{
  "insecure-registries" : ["registry:5000"]
}


Tip *To ssh in to minishift vm or any docker vm running via tool belt on windows,you can do this

locate the id_rsa for that machine in the user profile folder and fire a ssh.

//

ssh -i ~/.minishift/machines/minishift/id_rsa docker@url


=============================

If you are on windows with toolbelt, you can ssh into your boot2docker vm and update the /var/lib/boot2docker/profile  and add docker opts for insecure registry as shown below

DOCKER_OPTS="--insecure-registry url:5000"

restart docker service and test again by pushing the image.

You should be able to push your image now.


Ref url

you can test your repo availability by  

$curl url:Port/v2/_ping

$curl url:Port/v2/_catalog


Please not , you can also pull repository image in same docker environment and refer to the

registry container on localhost:5000 , that way you should be able to push it easily, pushing to external ip could have this allow unsecure access issues, locally it should work just fine. I fired up a vagrant box for openshift and i could pull a registry image , run a registry locally and push on localhost:5000 just like that, hey vagrant is awsome.. I just started using it.

Thursday, March 22, 2018

Play an mp3 file on raspberry pi remotely, use it as an alarm or to call some one

Get the apache2 and php from here


Create an index.php and place it in root, create the mp3 file and sh file which
will be played by the php, you can use mp3 recorder online to create a custom message
or alarm sound.

Use this link to create php file and I used omxplayer isntead of mpg123 mentioned, i got pi3



Well i could open this local ip of my pi and it played my sound remotely through a webpage,
I saved a bookmark on my android phone on home screen to use it handy.

Tip* You could also test your script and mp3 locally by running in shell before inserting it in php page.

I cam going to use it frequently to call my wife, she doesn't check her phone often and I am
too lazy to move from my couch.

In case you get some weird vchiq error  
* failed to open vchiq instance fix this here 

Oh and yes, i did a mac/ip binding on my dlink router so that my pi always picks up same
address, if you want to use it from outside home(remotely) you can do a port forward also.

Wednesday, March 21, 2018

Send http post webhook to Iftt maker channel service using motion library on Raspberry pi

In case you are using motion on raspberry pi and want to make a notification on
your android phone whenever some motion is detected on camera, please read this.


Go to ifttt and login and create a new applet , in this part select webhook 
enter the event name , ilke the front_door_movement and select a notification in that
part, for simple android notification on the phone select the ifttt notification (simple one)

Now go to settings and know your api key for this webhook.

The trigger url for webhook will look something like this.

ifttt.py  // run apt-get update & apt-get install python-requests if you dont have requests module on pi
////////
import requests
////////////


Go to /etc/motion/motion.conf and locate on_event_start event 

on_event_start  python /home/pi/ifttt.py

uncomment and add this trigger, make sure python file is executable by running chmod +x

try running file first to see if ifttt hook is setup properly.

Now whenever the motion is detected on the camera, this will send an android notification from the ifttt app.

Tested and it works perfectly.




Monday, March 19, 2018

Openshift Basics

Openshift is a PAAS solution by Redhat, platform as a service.

Openshift uses kubernetes and docker technology to provision containers.

Openshift is a wrapper around docker and kubernetes 

Openshift can be installed locally using minishift.

To run an  application you will need the following :

Project: A project need to be created for any app to run, it has its own namespace where resources will reside.

Route: To expose the service to outside world.

Pod: The node where containers run , one pod can have multiple containers.

ImageStream: is a link to the image from local registry or dockerhub 

YAML: The meta information for the resources , configuration file for resources

Services: The app hosted on pod can be termed as service.

Once the image is deployed either from docker repo or external registry, it is available in local repo as well 
Internal docker repo will have an assigned repo ip from the cluster.


Db pods usually share the gluster/ceph storage as shared SAN, they also have replication provision to achieve HA

Services running on one node can reference other services on another node of the cluster with the spec names.





Run a docker image on Openshift training environment from dockerhub

Get the client VM and the shared environment access, we will use client VM only to connect to the Openshift environment.

Note. IF you dont use shared environment access, you won't see an option to create the project in the console.

Create a new project from the console and search the image from the deploy image option.
Create the image in the openshift environment.
Create the route and map the application port, check route YAML for more information.
Access the application , make sure you use it directly and don't specify the port.

E.g if you bound 8001-->8001 of container try the http://routeurl:contextroot only