NodeJS development using Docker made simple.
This is a simple REST API built using Hapi.js. The microservice architecture allows it to be run using either Docker or docker-compose
.
The API is exposed to "the internets" via an NGINX reverse proxy and persistence is handled by a Redis server.
Settings are handled via environment vars, available config values are:
env | desc |
---|---|
PORT |
backend service port |
REDIS_URL |
uri for the redis server |
- clone the repo
cd
into the folderdocker compose up
- ?????
- Profit!
Now point your browser towards http://localhost:8080 🎉
If you're developing locally and just want to test the app in isolation, you can build the container via:
docker build -t <username>/<applicationName> --rm .
NOTE the optional --rm
flag, used here to remove the intermediate containers
This tells Docker to dockerize the entire folder application (.
) and name the container <userName>/<applicationName>
.
This is another Docker best practice, you can call your container as you see fit, but a pattern is using your Docker username and your application name joined by a slash (/
), ie:
docker build -t cilindrox/docker-sample .
Once the image has been built, you can run the container via the run
command:
docker run -d -p 8080:3000 <username>/<applicationName>
This will spin up a new container along with the Node application, mapping the port 3000
of the container to the port 8080
of the host.
You can verify this by typing docker ps
in your console.