Docker
For people who need to use N|Solid in a Dockerized environment, NodeSource has developed the N|Solid Docker images.
These images are built with the enterprise customer in mind, developing a versatile set of independently scalable Docker images that work together to provide a unified N|Solid experience across all of your Dockerized infrastructure.
In addition to being friendly to enterprise operations teams, the N|Solid Docker Images have been designed to be accessible to developers. For those who are already using Docker, these images provide an easy way to get up and running with the N|Solid console. With the use of docker-compose
, you can now get the full N|Solid Suite on your local
machine with a single command.
Overview of N|Solid Docker Images
We provide 3 separate Docker Images for N|Solid, allowing each component of the platform to be scaled and deployed independently.
Docker Image | Description |
---|---|
nodesource/nsolid | The base image that your Docker images should build from. It provides the N|Solid runtime and agent and needs to be properly configured to register its agent with the N|Solid Console service. Releases |
nodesource/nsolid-console | Contains the N|Solid console, a web-based interface for monitoring Node.js applications. You will need to bind the internal port 6753 to your host. Releases |
nodesource/nsolid-cli | Provides an easy way to query statistics from your Node.js processes. It is meant to be run directly from the command line and is optional. Releases |
All of the images are built on the official ubuntu:bionic
image maintained by the Docker project. The latest
tag defaults to the latest Node.js v20.x Iron LTS release. For more details please refer to the docker-nsolid github repository.
Installing the N|Solid Docker Images
Setting up Docker
First, follow the steps for installing Docker for your operating system.
Although not required, it is recommended that you use docker-compose
when first getting started. It simplifies managing these Docker images when running them locally.
Docker Compose
The docker-compose file below provides an example of the N|Solid platform configuration. It is also useful as a starting point for your docker setup.
The following docker-compose
file doesn't include any N|Solid applications yet. We will explain how to add your application below. Use a valid path in the volumes
configuration, or remove it if persistence is not important to you.
# nsolid.yml
version: "2"
services:
console:
image: nodesource/nsolid-console
container_name: nsolid.console
ports:
- 9001:9001
- 9002:9002
- 9003:9003
- 6753:6753
environment:
- NSOLID_CONSOLE_LICENSE_KEY=xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
volumes:
- /path/to/persistent/console:/var/lib/nsolid/console
networks:
- nsolid
networks:
nsolid:
Note: The NSOLID_CONSOLE_LICENSE_KEY
should be a valid license key not a JWT license token, you can see more information about license tokens here.
Downloading the Docker Images
To download the images using docker-compose
, open a terminal in the directory where nsolid.yml is kept, and run:
$ docker-compose -f nsolid.yml pull
This will download all of the images needed to run the N|Solid console locally.
To download the images using docker
, execute the following commands:
$ docker pull nodesource/nsolid-console
# Optional CLI
$ docker pull nodesource/nsolid-cli
Using the N|Solid Docker Images
Starting the N|Solid Console
With Docker Compose
To bring up the N|Solid Console, run the following command:
$ docker-compose -f nsolid.yml up
By default, this will bring up the N|Solid Console available on 127.0.0.1:6753
.
With Docker
Though using docker-compose
is our recommended approach for local development, the N|Solid console can be started with docker
:
# start console
$ docker run -d -p 9001-9003:9001-9003 -p 6743:6753 \
-v /path/to/persistent/console:/var/lib/nsolid/console --name console \
--network docker_nsolid \
nodesource/nsolid-console
This will bring up the N|Solid console available on localhost:6753
.
Make sure you have a Docker network to link your containers, you can create one with:
$ docker network create docker_nsolid
Visit the docker docs) for more information on Docker container networking.
Creating an Example Docker Application
Create a file called server.js
:
// server.js
var http = require('http');
var hostname = require('os').hostname();
var port = process.env.PORT || 8888;
var server = http.createServer(function handleRequest (request, response) {
response.end('[' + hostname + '] Serving requests from myapp. Request URL:' + request.url);
});
server.listen(port, function () {
console.log('Server listening on port', port);
});
Create a file called Dockerfile
:
# Dockerfile
FROM nodesource/nsolid
COPY server.js /server.js
EXPOSE 8888
CMD ["nsolid", "/server.js"]
Build docker image:
$ docker build -t example .
Starting Example Application with Docker Compose
Create the file docker-compose.yml in the directory along-side nsolid.yml:
# docker-compose.yaml
version: "2"
services:
example:
image: example
container_name: nsolid.example
ports:
- 8888:8888 # Port your application exposes
environment:
- NSOLID_APPNAME=example
- NSOLID_COMMAND=console:9001
- NSOLID_DATA=console:9002
- NSOLID_BULK=console:9003
networks:
- nsolid
networks:
nsolid:
For the complete documentation on defining a service with docker-compose.yml
, refer to the Docker project’s documentation page: https://docs.docker.com/compose/overview/.
At this point, you are ready to bring up your application using docker-compose
:
$ docker-compose -f nsolid.yml -f docker-compose.yml up
Starting Example Application with Docker
Start your service:
# start and connect your application to N|Solid
$ docker run -d --name example -e 'NSOLID_APPNAME=example' -e 'NSOLID_COMMAND=console:9001' -e 'NSOLID_DATA=console:9002' -e 'NSOLID_BULK=console:9003' --network docker_nsolid example
Adding Your Own Application with Docker Compose
If you are new to Docker, follow the steps in our blog post to get your application into a Docker container.
Your Dockerfile should begin with the following line:
#Dockerfile
FROM nodesource/nsolid
Congratulations, you are now up and running with N|Solid and Docker!