CableLabs Micronets

Developer documentation for CableLabs Micronets

Using Docker

Abstract

Docker images are created on development/build machines and published to a remote registry. On the deployment side, docker images are pulled from the remote registry, stored in the local registry and then instantiated at runtime as Docker containers.

Prerequisites

  • A private registry host, such as Artifactory or GitLab must be setup as place to store the docker images
  • Docker and all dependencies have to be installed on both build and deployment environments

Build Setup

In the root directory of the project, create a Dockerfile similar to this:

FROM node:8

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
COPY package.json .
COPY package.json package-lock.json ./

ENV mso_portal_url="http://localhost:3010"

RUN npm install

# Bundle app source
COPY . .

EXPOSE 3000
CMD [ "npm", "start" ]

Build the Docker image. It will be stored in your local Docker registry.

docker build -t community.cablelabs.com:4567/micronets-docker/micronets-reg-server .

Publish the Docker image to your remote registry.

docker login community.cablelabs.com:4567; docker push community.cablelabs.com:4567/micronets-docker/micronets-reg-server

Deployment

Docker containers can be named at runtime. Doing so will ensure that the container created with docker run can be stopped and restarted using the name given to the container. It also allows the container to be started and stopped using the standard unix systemd facility.

Docker image installation

To download a Docker image from a remote repository, use the docker pull command:

# Log in with your remote registry credentials
docker login

# Retrieve the image
docker pull community.cablelabs.com:4567/micronets-docker/micronets-reg-server:latest`

# Remove the container first, if it exists (cannot create a named container with the same name)
docker rm -f micronets-reg-server

# Run the image (create a container) and give it a name.
docker run -d --name=micronets-reg-server -e someenv -p 3000:3000 community.cablelabs.com:4567/micronets-docker/micronets-reg-server:latest

Create a systemd configuration file

This will ensure that your Docker container will start every time the system reboots. Add a configuration file: /etc/systemd/system/micronets-reg-server.service

[Unit]
Description=Micronets Registration Server Container
Requires=docker.service
After=docker.service

[Service]
Restart=always
RestartSec=5
ExecStart=/usr/bin/docker start -a micronets-reg-server
ExecStop=/usr/bin/docker stop -t 2 micronets-reg-server
ExecRestart=/usr/bin/docker restart -t 2 micronets-reg-server

[Install]
WantedBy=default.target

Enable the service

sudo systemctl enable micronets-reg-server

Starting and Stopping your container

# systemd
sudo systemctl start micronets-reg-server
sudo systemctl stop micronets-reg-server
sudo systemctl restart micronets-reg-server

# docker
docker start -a micronets-reg-server
docker stop -t 2 micronets-reg-server
docker restart -t 2 micronets-reg-server