Skip to main content

Installing the Docker environment

It guides you how to create a DockerFile in the Docker environment to install and run the Node.js agent. For the example file used in the following guide, see the following link.

File structure

The Node.js agent's sample file has the structure as follows.

  • html: Sample application folder.

  • Dockerfile: Configuration file to build the Docker image.

  • http.js: Sample application file.

  • package.json: Document for the sample application information and dependency management.

  • whatap.conf: Option configuration file for monitoring.

  • security.conf (or paramkey.txt): Parameter encryption key.

Installing the agent

Add the Node.js agent in the package.json file or execute the npm installation command.

package.json
"dependencies": {
"whatap": "^0.4.72"
}
npm install --save whatap

Container image building

Write the Docker file to build the image.

Dockerfile
FROM node:latest

WORKDIR /app
ADD . .

RUN npm install

CMD ["node","http.js"]

Build

Execute the build command.

$ docker build -t sampleapp/nodejs:0503 .

Execution

Start the container by setting the collection server IP and access key in the environment variables. The application runs along with the Node.js agent.

export WHATAP_LICENSE={access Key}
export WHATAP_SERVER_HOST={collection server IP}

$ docker run --rm -p 3500:3500 \
-e whatap_server_host=$WHATAP_SERVER_HOST \
-e license=$WHATAP_LICENSE \
sampleapp/nodejs:0503