Lab 1 - Start with a Docker Image
This Lab will help you understand basics of Docker technology, you will build, ship, and run a container image.
Last updated
Was this helpful?
This Lab will help you understand basics of Docker technology, you will build, ship, and run a container image.
Last updated
Was this helpful?
This workshop is an introduction to Docker, which is a runtime for containers. You will create a containerized Node.js application that provides a service to translate phrases from one language to another. The application uses the IBM Watson in .‌
For this Lab you will use Docker.
Docker technology virtualizes the Operating System (OS), and thanks to it only the application, and specific dependencies like libraries and binaries are being packaged in the image.
Starting such an image is much faster omitting start of an OS. In addition the image now is very portable among various host servers running the Docker engine. And since ther is no OS, there isn't its surface for security vulnerabilities connected to it.
The following steps would allow you to create the Watson translation service in the cloud. You will record the API Key to access your service later. You will create a node.js based microservice. This microservice will respond to requests with results of the translations coming from IBM Watson service. As soon as you are ready with the microservice you will be able to start Build - Ship - Run containerization process. You will build an image, and push it to a public repository - Docker Hub, and run the containerized microservice.
Search translator to find the 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.
You will be redirected to the service landing page.
Click on Service Credentials on the left bar.
If you do not see a credential provided for you, you can create a new set of credentials. Save your apikey and url values 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!
Change into the directory you just cloned and build the docker image
Alternatively, you can also build directly from github using the following command without cloning the repository:
This command uses the Dockerfile to download a Node.js 10 base image and then install our Express.js application on top.
Let's explore the contents of this Dockerfile
:
FROM node:10
... builds our image on top of the Node.js 10 image.
WORKDIR /usr/src/app
... creates a working directory for our application to live in.
COPY package*.json ./
... copies the package.json file to our working directory. RUN npm install ... install our dependencies. We just have two dependencies in this application: express and ibm-watson.
COPY . .
... copy the rest of our source code into the docker image
EXPOSE 8080
... expose port 8080. We will still have to forward our local port to this docker container port later.
CMD [ "node", "server.js" ]
... starts the application by running node server.js.
In my case, I would run
You should see output as follows:
The text is translated to Spanish (en-sp)
by default. You can specify the langauge by passing in the lang flag as follows:
You should now see the same text translated to German:
Another example ...
in Polish
Congratulations! You just containerized a Node.js application that provides transation services.
You can first stop the container. You need the container tag or the id to stop it. Let's look it up first
In my case, the container is called cranky_davinci
and has an id of 419104eff9be
.
Stop the image with the following command. You can replace the id with your container id.
Run the following command to remove the container. Replace the id with your container id identified in the step above.
You can now delete the image. You again need the image id.
Now, delete the image as follows.
You can check the logs for your container using
For example ...
Congratulations again on creating your first docker container that hosts a Natural Language Translation service!
Please claim your pre-provisioned cluster, and set up your environment for the next labs.
‌Open your IBM Cloud dashboard using your IBM Cloud account with this URL: : .
Open your local terminal and clone the reposiotry with the example (you might want to use git, or simply download the zip file from the following location ).
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.
You can see the supported languages (both from and to)
in the .
In order to read and learn more about Docker - please use this link: ​