During many customer discussions on PaaS, the same question does come up:
“Can I use my own Docker images in OpenShift?”
While the simple answer obviously is:
Making it work, is a little bit more complex – until one finally understands it.
… this was done with lots of help from Michal Fojtik. Michal, thanks a lot!!!
The image which I want to us is on a different system, which is in no way connected to my OpenShift environment. Therefor saving the image into a file is the first thing to do:
[psteiner@demo ~]# docker save <name_of_image> > export.tar
After copying the tarbal to the OpenShift Master, you can load it into the local Docker repository
[root@master ~]# docker load < export.tar
Before we continue, lets login to our OpenShift V3
[root@master ~]# oc login Username: psteiner
At this point we can also login to our OpenShift registry. To do so, first we need to get the token for our user
[root@master ~]# oc whoami -t QSbfzkT3yPaScbxRodIGa5bNYvUsqfvA6VNdh1tGtFU
and use the token for the login to the registry
[root@master ~]# docker login -u psteiner -e email@example.com -p QSbfzkT3yPaScbxRodIGa5bNYvUsqfvA6VNdh1tGtFU 172.30.80.73:5000 WARNING: login credentials saved in /root/.dockercfg. Login Succeeded
The IP-Address at the end of the command is for our OpenShift registry and port.
For the image to be able to be pushed to the registry, there needs to be OpenShift project. The name of this project will be used as a namespace during the following steps.
[root@master ~]# oc new-project iotdemo
Now we need to put a Tag to our local image, giving it the name for later usage.
[root@master Downloads]# docker tag iotcontroller 172.30.80.73:5000/iotdemo/iotcontrollerreceiver
The last step is the push itself – we are nearly there!
[root@master Downloads]# docker push 172.30.80.73:5000/iotdemo/iotcontrollerreceiver The push refers to a repository [172.30.80.73:5000/iotdemo/iotcontrollerreceiver] (len: 1) def452b4ada4: Image already exists f108b4ea3dbd: Image successfully pushed 47d44cb6f252: Image successfully pushed Digest: sha256:ed928660aa37aa1fb576c7edc78ca055df87a940a99d9ac2123005a5a2697862
This procedure does not only push the image to the OpenShift registry, but also creates an ImageStream, which you can later reference in your templates, etc.
Running the following command will verify this
[root@master Downloads]# oc get is NAME DOCKER REPO TAGS UPDATED iotcontrollerreceiver 172.30.80.73:5000/iotdemo/iotcontrollerreceiver latest 52 seconds ago
Step 8 ( optional )
If your Docker image is build in a way that use use the “USER” command and rely on the image to be run in that user-context, you will have to relax the security to allow that. There is a nice, simple section in the documentation, explaining how to!
Now you are ready to use the image and the ImageStream.