Skip to content

Run Nodes in docker containers for test

pojashad edited this page Feb 1, 2019 · 12 revisions

These instructions is suited for running a bunch of nodes in separate containers.

Create a docker file

  1. Create a file called "Dockerfile" with the following content:
FROM node:8
RUN npm install microservicebus-node
COPY entrypoint.sh /
ENTRYPOINT ["/entrypoint.sh"]
  1. Create a file called "entrypoint.sh" with the following content:
#!/bin/sh
echo "$1"

cd node_modules/microservicebus-node
export NODE_PATH=/usr/local/lib/node_modules
node start -c $1 -n $2

when the file is created run:

chmod +x entrypoint.sh
  1. Create a docker image:
docker build -t msb .
  1. Create your node and generate a code
  2. Create a node container:
docker run -d --name [NODENAME] msb [CODE] [NODENAME]
# Eg.
docker run -d --name node-00001 msb QQIN643B node-00001
  1. To stop the container:
docker stop node-00001

# Stop all containers:
docker stop $(docker ps -q)

# Start 100 at the time:
docker stop $(sudo docker container ls -q --filter status=exited --filter name=node-000[0-9])
docker stop $(sudo docker container ls -q --filter status=exited --filter name=node-001[0-9])
docker stop $(sudo docker container ls -q --filter status=exited --filter name=node-002[0-9])
docker stop $(sudo docker container ls -q --filter status=exited --filter name=node-003[0-9])
  1. To start the container:
docker start node-00001

# Start all containers:
docker start $(docker ps -a -q)

# Start 100 at the time:
docker start $(sudo docker container ls -q -a --filter status=exited --filter name=node-000[0-9])
docker start $(sudo docker container ls -q -a --filter status=exited --filter name=node-001[0-9])
docker start $(sudo docker container ls -q -a --filter status=exited --filter name=node-002[0-9])
docker start $(sudo docker container ls -q -a --filter status=exited --filter name=node-003[0-9])
  1. To start container i bash:
docker run --entrypoint /bin/bash -i -t msb

Tool tip

Random commands that is good to know:

Start containers that is NOT running and has a specific name. Use numbers in [ ] to fine grain what nodes you want to start:

sudo docker start $(sudo docker container ls -q --filter status=exited --filter name=node-001[3-5])

View CPU/MEM stats of specific containers:

sudo docker stats $(sudo docker ps -q -f name=node-002) --no-stream 

Attach with bash to an existing started container:

docker exec -i -t node-00001 /bin/bash
Clone this wiki locally