📜 ⬆️ ⬇️

Quick start for custom docker container on OpenShift platform

There was a need to create a cloud service and for the implementation of this project open source solution was chosen OpenShift. After successfully passing Getting Started and deploying HelloWorld, unexpected difficulties arose: the official documentation required detailed study to solve such a simple task as raising your own ready container with arbitrary content. It was necessary to understand a little and below the simple ready manual. It is understood that the reader is familiar with docker, because There are no explanations of his commands in this manual.

Install docker


It is enough to use the official documentation and do everything according to the instructions. There should be no problems.

We create docker-image with the application


I compiled my image with a Java application written using the Spring-Cloud framework. This is the implementation of the Config-Server. I will have the name image config-server.
')

Install OpenShift


For my purposes, I chose the installation via the launch of the docker container (enough for the dev). Everything is simple (all information is for Linux):
$ docker run -d --name "origin" \ --privileged --pid=host --net=host \ -v /:/rootfs:ro -v /var/run:/var/run:rw -v /sys:/sys -v /var/lib/docker:/var/lib/docker:rw \ -v /var/lib/origin/openshift.local.volumes:/var/lib/origin/openshift.local.volumes \ openshift/origin start 

After the container rises, the web interface will be available at
 https://localhost:8443 

image

Log in (login: admin, password: admin).
image

We create the project OpenShift


There are 2 ways: from the command line and through the web interface. I recommend the first way, especially since all the same the following points must be performed from the command line. Let's leave the web-interface for monitoring.
Launch a separate terminal window and do not close it until the end of all operations; use this window only for working with the OpenShift service.

So we get into the opened OpenShift container:
 $ docker exec -it origin bash 

Log in to the OpenShift service (login: admin, password: admin)
 $ oc login 

Create a project
 $ oc new-project config-server --description="Spring Cloud Config-Server" --display-name="Main config-server" 

image
Create pod.json
 $ vi pod.json 

inside:
 { "kind": "Pod", "apiVersion": "v1", "metadata": { "name": "config-server", "creationTimestamp": null, "labels": { "name": "config-server" } }, "spec": { "containers": [ { "name": "config-server", "image": "config-server", "ports": [ { "containerPort": 8888, "protocol": "TCP" } ], "resources": {}, "volumeMounts": [ { "name":"tmp", "mountPath":"/tmp" } ], "terminationMessagePath": "/dev/termination-log", "imagePullPolicy": "IfNotPresent", "capabilities": {}, "securityContext": { "capabilities": {}, "privileged": false } } ], "volumes": [ { "name":"tmp", "emptyDir": {} } ], "restartPolicy": "Always", "dnsPolicy": "ClusterFirst", "serviceAccount": "" }, "status": {} } 

Pay special attention to the following elements:
"Image": "config-server" (should coincide with the name of our docker-image)
"ContainerPort": 8888 (the port that will be open for access to your application)
"Protocol": "TCP" (protocol)
 $ oc create -f pod.json 

image

Now you need to look in the web console to make sure that everything is in order (Browse -> Pods -> config-server):
image

As you can see from the screenshot, my service is available at:
 http://172.17.0.2:8888 

If we dwell on this product and continue development, it will be possible to continue the publications in this series.

Thanks for attention!

Source: https://habr.com/ru/post/281979/


All Articles