Use Case: As a developer, I wish to create container images using JBDS and deploy them to OpenShift
Step 1: Switch to Docker perspective
On the top right of JBDS you will find icons to switch perspectives. Find the Docker Tooling
icon that appears as a single blue cylinder. If you hover over the icons it should show the label Docker Tooling
. You can also open this by going through menu options Window
->Perspective
->Open Perspective
->Other
and select Docker Tooling
.
Step 2: Create a connection to the Docker Daemon running on the Minishift VM
Minishift runs a VM, and a docker daemon inside that VM. oc cluster up
that is run by minishift pulls the OpenShift all-in-one and instantiates using this docker daemon. While you may have Docker running on your workstation (example Docker on Windows or Docker on Mac), Minishift doesn't use that daemon. In this step, we will connect to this daemon from JBDS.
- To find the connection details run the following command from your command line to gather minishift's docker connection details.
$ minishift docker-env
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.64.2:2376"
export DOCKER_CERT_PATH="/Users/veer/.minishift/certs"
export DOCKER_API_VERSION="1.24"
# Run this command to configure your shell:
# eval $(minishift docker-env)
Note the values for DOCKER_HOST
and DOCKER_CERT_PATH
. In my case they are
tcp://192.168.64.2:2376
and /Users/veer/.minishift/certs
- In the
Docker Explorer
, press on theAdd Connection
icon (blue cylinder with a yellow + sign).
- This will open up
Connect to docker daemon
window. Now provide aConnection name
and type in the connection parameters noted above forTCP Connection
. CheckEnable Authentication
and provide theDOCKER_CERT_PATH
noted above.
-
Press on
Test Connection
to ensure that the connection is successful. Then press onFinish
-
Docker Explorer
view on the left should now show the connection that you just created. Expand the same and navigate through theImages
andContainers
to get accustomed to this view.
Step 3: Create an Application Container Image
We will use a Dockerfile to create a container. I have a simple example here https://github.com/VeerMuchandi/time that has a Dockerfile based on busybox as the base image. If you are using Minishift with CDK, you can use rhel based image.
- Let us switch back from the
Docker tooling
perspective back toJBoss
perspective by clicking on the red dots icon.
- Right click in the
Project Explorer
view and selectImport
->Import
. ChooseGit
andProjects from Git (with smart import)
and theNext
button - You'll see
Select Repository Source
window. ChooseClone URI
and pressNext
again - Next you'll see
Source Git Repository
window. Copy paste https://github.com/VeerMuchandi/time in theURI
and press onNext
and againNext
in theBranch Selection
window - Choose a directory for
Local Destination
or leave it as defaults and pressNext
and Finish on the next window.
This will import the git repository with code and make it available via Project Explorer
. We are interested in the Dockerfile
in the busybox
folder. Open the same.
- Now let's switch back to the
Docker Tooling
perspective - Right click on the
Dockerfile
and selectRun As
->Docker Image Build
- You'll see
Edit Configuration
window. Give aName:
to the image (I called itbbtime
) and select theDocker Connection
to point to the Minishift daemon that you configured earlier. Ensure theBuild Context Path
is set correctly and press onRun
- The docker build should now start and you will see the output in the
Console
view at the bottom - Now use
Docker Explorer
and navigate toImages
in the Minishift Docker Daemon that you configured earlier. You should find the new image that you just created (bbtime
) there.
Step 4: Deploy the container image into OpenShift
In order to deploy this image we will tag it and push it into the openshift internal registry first.
-
Go to
OpenShift Explorer
view at the bottom and find the OpenShift connection to the Minishift Cluster. This OpenShift connection should showMy Project
. Right-click on the OpenShift Connection and chooseNew
->Project
. Provide a name for the project. I'll call itnewproject
and give aDisplay Name
ofMy New Project
and press onFinish
. JBDS will create a new project on the OpenShift cluster. We will use this project to deploy our application using the container image. -
Based on what you learnt in chapter 2, you know how to find the registry service IP. Usually it is set to
172.30.1.1
by default and exposes port5000
. Let's now retag the image as172.30.1.1:5000/newproject/bbtime:latest
where172.30.1.1:5000
is the container registry running on OpenShift andnewproject
is the namespace. In theDocker Explorer
view select the image (bbtime
) created in the previous step, right-click on the same andAdd Tag
. Fill theNew Tag
fied with the value172.30.1.1:5000/newproject/bbtime:latest
and pressFinish
. -
Our next step is to Push this tagged image. Find the image with tag
bbtime:latest
in the images list and right click on it and selectPush
. You will be taken toPush Image
window. Usenewproject/bbtime:latest
forImage Name
. We will need token fromoc login
to use as password here. So go to command line and runoc whoami -t
to find the token. Fill inServer Address
with the registry address i.e172.30.1.1:5000
, and Username asdeveloper
and use the token as thePassword
. Then press onFinish
to push the image to atomic registry on OpenShift.
- If you check now in the new-project, you should see the image stream in place
$ oc project newproject
Now using project "newproject" on server "https://192.168.64.2:8443".
$ oc get is
NAME DOCKER REPO TAGS UPDATED
bbtime 172.30.1.1:5000/newproject/bbtime latest 4 minutes ago
- In order to deploy the application, navigate to the
Docker Explorer
view, right click on the172.30.1.1:5000/newproject/bbtime:latest
in the images list and selectDeploy to OpenShift
. - You'll see
Deploy an Image
window. Make sure that you are using thenewproject
andImage Name
is pointing to172.30.1.1:5000/newproject/bbtime:latest
and pressNext
- Click
Next
again twice to accept the defaults on theDeployment Configuration
andService and Routing Settings
windows - On the next screen let's add a label
app=bbtime
and press onFinish
. This will deploy the docker image as a new application.
- Now if you go to
OpenShift Explorer
view and navigate tonewproject
you should see thebbtime
service running. Right click on the service andShow In
->Web Browser
to view the running application.
Summary: In this chapter, we learnt to set up connection to a docker daemon running on minishift from JBDS. Then built a container image on JBDS, tagged and pushed it into an OpenShift project to create an image stream. Then we deployed the application into this project.