Skip to content
Developerhome
X3

Dockerizing the demo app

  Less than to read

In this last step, you will lear how to package the demo app as a docker container. You need a Dockerfile to define the Docker container:

  # To build use docker build -t repository.sagex3.com/x3-cloud-metrics:latest . in the current directory

  FROM node:12-stretch

  USER root

  ENV LAST_UPD=VERSION-24-09-2020

  RUN apt-get -y update
  RUN DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade


  #dumb-init entrypoint
  ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 /usr/local/bin/dumb-init
  RUN chmod +x /usr/local/bin/dumb-init

  COPY nodejs/package.json /nodejs/package.json
  COPY bootstrap.sh /

  RUN chmod +x /bootstrap.sh

  WORKDIR /nodejs
  RUN node -v
  RUN npm -v
  RUN npm install

  COPY nodejs /nodejs

  WORKDIR /

  RUN ls

  ENTRYPOINT  ["/usr/local/bin/dumb-init" , "--", "/bootstrap.sh"]

And a bootstrap.sh as the entrypoint of that Docker container.

#!/bin/sh

cd /nodejs
npm start

These 2 files are placed at the same level of nodejs folder and need to be saved under UNIX format (with LF ending character). Now you will build your docker container:

  docker build -t demo-app:latest .

Then start the container with the right parameter on:

  • “ENDPOINT_URL”: API Gateway of the sandbox environment

  • “CLIENT_ID”: your App ID

  • “CLIENT_SECRET”: your App secret

docker run -p 5050:5050 -e ENV_URL='https://localhost:5050' -e COLOR='Demo App' -e APPLICATION='green' -e ENDPOINT_URL='ENDPOINT_URL' -e CLIENT_ID='CLIENT_ID' -e CLIENT_SECRET='CLIENT_SECRET' demo-app:latest

Now you have a docker container deployed at https://localhost:5050 with the same functionality as your VSCode launched version.

You can also download the VSCode project at the end of this step here.