Step 3: Build and Run a Docker Image
Last updated
Was this helpful?
Last updated
Was this helpful?
In this step, we'll create a containerized Node.js application that provides a service to do on-the-fly language translation. This service can later be deployed into an infrastructure composed of microservices, if desired. The application uses the .‌
For this Lab, we will use Docker.
To download docker onto your local system, .
Thanks to Docker containers, only the application, and specific dependencies like libraries and binaries are being packaged in the image.
First, we will create the Language Translation service and record the API Key to access your service later. Then we will create a node.js based microservice. This microservice will respond to requests with results of the translations coming from IBM Watson. As soon as you are ready with the microservice you will be able to start the Build - Ship - Run containerization process. You will build an image, and push it to a public repository (Docker Hub) and run the containerized microservice.
Open your IBM Cloud dashboard and click Catalog.
Search for translator to find the appropriate service. (You can also find the service by navigating to the AI section on the left bar.)
Click on the service to create a new instance. Pick the Lite free of charge plan on the next page and click Create to finish creating the service.
Next, we'll copy down the credentials for the new service that we've created. Click Service credentials in the left hand menu:
If you do not see a credential provided for you, you can create a new set of credentials. Save your apikey somewhere for the next section in this workshop.
Congratulations! You created your first Language Translator service. The next steps will show you how to build a Docker container for a Node.js application that provides an end point to translate text!
The cloud-hosted language translation service isn't very interesting by itself; we'll need to write a microservice for our application to call the language translator and get back the output. Luckily, we've written a microservice for you in a GitHub repo; all you have to do is package it into a Docker container.
Open your local command line and change to the /data
directory.
Now that we've cloned our repo, we'll build a docker image:
Alternatively, you can also build directly from github using the following command without cloning the repository:
Congratulations, you've created a docker image! Now, let's run it:
Remember to replace <api_key>
and <docker_username>
with your respective credentials.
Once your container is running, we can test the application:
You should see output as follows:
Congratulations, your microservice is now running in a Docker container and pinging a IBM Watson cloud language translation service! Next, we will focus on deploying containers into a Red Hat OpenShift environment.
The docker-username
is required if you want to publish your image to . Replace <docker-username>
in the above command with your docker account name.