Adding/setting insecure-registry to docker machine afterwards

Running docker on non-Linux based environment became very convenient and easy with docker-machine which is the successor of docker-boot.

Basically, docker-machine allows you to manage multiple virtual machines running Linux to host your docker installation and then allows you to run your containers.
More than a fantastic tool for OSX and Windows, it is also a very clever and practical way to develop multiple container images or several applications (for different project for examples) using containers.

If you want your docker-machine to use an your own in-house registry or any other, it is not a big issue, until the registry uses HTTPS, and in most of the cases you will get the following error:

docker tag -f my-app/my-app-server:v1.0.14-25-gfefb196 dockerhub.rnd.mycompany.net:5000/my-app/my-app-server:v1.0.14-25-gfefb196
docker push dockerhub.rnd.mycompany.net:5000/my-app/my-app-server:v1.0.14-25-gfefb196
The push refers to a repository [dockerhub.rnd.mycompany.net:5000/my-app/my-app-server] (len: 1)
unable to ping registry endpoint https://dockerhub.rnd.mycompany.net:5000/v0/
v2 ping attempt failed with error: Get https://dockerhub.rnd.mycompany.net:5000/v2/: x509: certificate signed by unknown authority
 v1 ping attempt failed
 with error: Get https://dockerhub.rnd.mycompany.net:5000/v1/_ping: x509: certificate signed by unknown authority

For this case, docker-machine has a fantastic option which is available on creation of a machine:

docker-machine create --driver virtualbox --engine-insecure-registry myregistry:5000 mycompany

But, suppose that you want to add another registry once your docker-machine is created: Unfortunately, I can’t find an option yet to edit the existing configuration of a VM.
You will have to edit your configuration file which is located on your host system (your OSX or Windows home) and add it manually:

vim  ~/.docker/machine/machines/mycompany/config.json

Then, you’ll have to edit the config.json file and locate the array named:InsecureRegistry and simply append an element on it.
It should looks like this:

{
  "ConfigVersion": 1,
 // Truncated for readability 
  "DriverName": "virtualbox",
  "HostOptions": {
    "Driver": "",
    "Memory": 0,
    "Disk": 0,
    "EngineOptions": {
      "ArbitraryFlags": [],
      "Dns": null,
      "GraphDir": "",
      "Env": [],
      "Ipv6": false,
      "InsecureRegistry": [
        "dockerhub.rnd.mycompany.net:5002",
        "dockerhub.rnd.mycompany.net:5000",
        "dockerhub.rnd.mycompany.net:5001"
      ],
      // Truncated for readability 
  },
  "StorePath": "/Users/Akram/.docker/machine/machines/mycompany"
}

OpenShift cheat sheet for beginners

Here is a simple cheatsheet for OpenShift beginners that will help you to visualise some basic settings about your projects, applications, pods in order to debug or get informations about how they behave.

Listing all your projects

oc get projects

This will give you the list of all the project that you can work on an highlight the current project.

Positioning the current project

oc project my-project

This will switch you current project to my-project. This settings is save in your ~/.kube/config file, so if multiple persons are using oc simultaneously with the same user, just mind no overriding each other.

Listing the existing pods (applications)

oc get pods

This will list all the pods (a wrapper for containers, even if generally 1 pod = 1 container) and show you status for each of them.

Checking status for pod

oc describe pod 

This will display information about the pod lifecycle: the node on which it has been scheduled, the status of the docker image on the node (image existing or pulling or failed to be pulled), the readiness and liveness status, and if the pod is started or stopped.

Watching pods logs

oc logs -f 

The -f option is for follow, just like for the tail command. This will display the logs sent to stdout from the container.
If the pod has crashed or has stopped, it will be in a state that would prevent seeing logs unless you specify -p (for –previous) option.

oc logs -p 

Watching event on project

oc get events -w

This will show you all the OpenShift events occurring on the current project and keep watching it (-w for –watch). The evens includes scheduling events, pod startup, scheduling, etc…

Hope that this will help every beginner.