Skip to content
No description, website, or topics provided.
Dockerfile Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
images adding in pid image Nov 12, 2019
.DS_Store adding in pid image Nov 12, 2019
Dockerfile initial add Oct 22, 2019
README.md Update README.md Nov 21, 2019
README.md-old.md updating readme to fix arch diagram Oct 31, 2019
createschema.sh initial add Oct 22, 2019
draft-pattern-template.md initial add Oct 22, 2019
readme-template.md initial add Oct 22, 2019
sql_script.txt initial add Oct 22, 2019

README.md

Build Status

Deploy containerized IBM Db2 Movie Database with Node.js API Restful Service

Containerization allows developers to create and deploy applications faster and more securely. With traditional methods, code is developed in a specific computing environment, which, when transferred to a new location, often results in bugs and errors. Containerization eliminates this problem by bundling the application code together with the related configuration files, libraries, and dependencies required for it to run. This single package of software, also known as a "container," is abstracted away from the host operating system, and hence it stands alone and becomes portable -- able to run across any platform or cloud, free of issues.

One tool that allows you to run containers is Docker, which is open source software that's designed to make it easier to create, deploy, and run applications using containers. LinuxONE was built for open source, so you can harness the agility of the open revolution on the industry's most secure, scalable, and high-performing Linux server. In this journey, we will show you how to run open source Db2 and Node.js Docker images on LinuxONE using Docker.

When you have completed this code pattern, you will understand how to:

  • Register for a free LinuxONE community Cloud Virtual Machine
  • Set up a Db2 container using Docker
  • Run a Node.js app in a Docker container that exposes the Db2 container to RESTful API services

Flow

architecture

  1. Register a RHEL instance on the LinuxONE Community Cloud.
  2. Install Docker.
  3. Create a Db2 database container using Docker.
  4. Populate the database container with movie records.
  5. Deploy a Node.js app container that exposes the Db2 database container to an API RESTful service.
  6. Test the environment using postman and/or your web browser.

Prerequisites

  • Register at LinuxONE Community Cloud for a trial account. You will be using a Red Hat base image for this journey, so be sure to choose the "Request your trial" button on the left side of this page.

  • Create your LinuxONE guest Remember to select RHEL instaead of SUSE.

  • (Optional) Install MobaXterm (Only on Windows)

Install Docker

First we need to change our user to root before installing docker to avoid any permission denied errors. Always make sure you're on root for the rest of the code pattern when executing commands.

sudo su

Install "GNU Wget" if it's not already installed. Wget is a free software package for retrieving files using HTTP, HTTPS, FTP and FTPS the most widely-used Internet protocols.

yum -y install wget

Download the correct Docker package archive using Wget.

wget ftp://ftp.unicamp.br/pub/linuxpatch/s390x/redhat/rhel7.3/docker-17.05.0-ce-rhel7.3-20170523.tar.gz

Then, unpack the archive and copy the Docker binaries:

tar -xzvf docker-17.05.0-ce-rhel7.3-20170523.tar.gz
cp docker-17.05.0-ce-rhel7.3-20170523/docker* /usr/bin/

And then start the Docker daemon:

docker daemon -g /local/docker/lib &

You should see something similar to this:

[root@devjourney07 ~]# docker daemon -g /local/docker/lib &
[1] 2332
[root@devjourney07 ~]# INFO[0000] New containerd process, pid: 2338

WARN[0000] containerd: low RLIMIT_NOFILE changing to max  current=1024 max=4096
WARN[0001] devmapper: Usage of loopback devices is strongly discouraged for production use. Please use `--storage-opt dm.thinpooldev` or use `man docker` to refer to dm.thinpooldev section.
INFO[0001] devmapper: Creating filesystem xfs on device docker-94:2-263097-base
INFO[0001] devmapper: Successfully created filesystem xfs on device docker-94:2-263097-base
INFO[0001] Graph migration to content-addressability took 0.00 seconds
INFO[0001] Firewalld running: false
INFO[0001] Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set a preferred IP address
INFO[0001] Loading containers: start.

INFO[0001] Loading containers: done.
INFO[0001] Daemon has completed initialization
INFO[0001] Docker daemon                                 commit=b9f10c9-unsupported graphdriver=devicemapper version=1.11.2
INFO[0001] API listen on /var/run/docker.sock

When you reach this point press Enter key to continue.

Steps

Follow these steps to set up and run this code pattern. The steps are described in detail below.

  1. Clone the Db2 repo.
  2. Set up your Db2 container.
  3. Clone the Node.js app repo.
  4. Build and run the Node.js app.
  5. Test the environment.

1. Clone the Db2 repo

Clone the imdb_lite repo after logging into your LinuxOne Community Cloud Rhel Virtual Machine. In a terminal, run:

git clone https://github.com/codesenju/imdb_lite.git
cd imdb_lite

Please click here to download the movie data file "data.tar.gz", which has the records for the movie database. You do not have to sign up for an account to download.

  • Either using MobaXterm or your favorite secure copy client, copy the data.tar.gz file to your LinuxONE Virtual Machine.

  • Showing how you can drag and drop the data.tar.gz into your folder /imdb_lite using MobaXterm.



  • Alternatively you can copy data.tar.gz from your terminal into your folder /imdb_lite using scp command:
scp -i {location of .pem Key file} {location of data.tar.gz}  linux1@{ip address of LinuxONE Virtual machine}:/home/linux1
  • Log into your LinuxONE Virtual Machine and move the data.tar.gz file to /home/linux1/imdb_lite or to wherever your imdb_lite folder is located.
sudo su
mv /home/linux1/data.tar.gz /home/linux1/imdb_lite/
cd /home/linux1/imdb_lite
  • Run the command ls -alh to view the directory contents. Check and see if your directory looks similar. It's ok if you see more files than the below image, you can move on to the next step and build your Db2 image.

imdb_lite_dir

2. Set up your Db2 container

  • Build your Db2 image.
    docker build command will build the images automatically by reading the instructions from a Dockerfile -- a text file that contains all commands, in order, needed to build a given image. The first command 'FROM' is a instruction telling docker which base image to pull from docker hub of which for this example we using IBMCOM/Db2 base image.
rm -rf images/ #first lets remove unnecessary files
docker build -t codesenju/imdb_lite .


  • After successful build, run the command docker images to see your image loaded into Docker. On completion, you should see the following output on the console:

docker_images

  • Create a container network that will be used by your two microservices.
docker network create mynet
  • Run your Db2 image as a container.
docker run -itd --net mynet --name micro_db2 --privileged=true -p 50000:50000 -e LICENSE=accept -e DB2INST1_PASSWORD=db2admin -e DBNAME= -v /usr/src/app:/database codesenju/imdb_lite


  • After successfully executing the last command, you can check to see if you have a container instance of Db2 running by executing the following command:
docker ps
  • You should see the following output on your console:

dockerps_imdblite

  • Now you need to log into the Db2 container and configure the database schema. Replace {CONTAINER-ID} with the correct container id yours will look different.
docker exec -ti {CONTAINER-ID} bash -c "su - db2inst1"
cd /var/custom
db2 -tvf sql_script.txt
  • db2 -tvf is a Db2 command that runs a custom made sql script and in this example we will be using sql_script.txt that has already been copied while we were building the Db2 image.

  • sql_script.txt contains all the instructions for the Db2 server for creating a database, schema, two tables and importing movie data from basics.ixf and actors.ixf files.

sql_script.txt:
CREATE DATABASE MOVIE;
CONNECT TO MOVIE;
CREATE SCHEMA MOVIE;
IMPORT FROM basics.ixf OF IXF
REPLACE_CREATE



  • When you're done, exit the container with exit.

3. Clone the Node.js app repo

cd ~
git clone https://github.com/codesenju/nodejs_api4db2.git
cd nodejs_api4db2

4. Build and run the Node.js app

docker build -t codesenju/nodejs_api4db2 .
docker run --net mynet -p 49160:8081 -d codesenju/nodejs_api4db2


5. Test the environment

  • Test within the LinuxONE machine using cURL:
curl localhost:49160
curl localhost:49160/api/all


  • Test from any browser by entering the following URL:
<vm-ip>:49160/ # replace <vm-ip> with your LinuxOne machine IP address.
<vm-ip>:49160/api/all


  • Test with Postman. You can download postman here:
<vm-ip>:49160/ # replace <vm-ip> with your LinuxOne machine IP address.
<vm-ip>:49160/api/all



Troubleshoot

Re-Installing Docker

First remove docker and all it's instances. Execute top | grep docker and wait at least 15 seconds to see if there is any docker deamon processes running in the background or not.


pid

If you see any processes running in the backround similar to the image above, kill the processes by executing a simple kill command and specify which process id. Replace {process-id} with the correct process id.

kill {process-id}

After remove other docker files.

rm -rf /usr/bin/docker*
rm -rf /local/docker

Now you are ready to install docker again.

License

This code pattern is licensed under the Apache License, Version 2. Separate third-party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 and the Apache License, Version 2.

Apache License FAQ

You can’t perform that action at this time.