In this quickstart guide, you will see how to build a Node.js application (visitor counter) using Nginx, Redis and Docker.
- Nginx: An open source software for web serving, reverse proxying, caching, load balancing, media streaming, and more.
- Docker: a containerization platform for developing, shipping, and running applications.
- Docker Compose: A tool for defining and running multi-container Docker applications.
– Install Docker Desktop
Use Docker's install guide to setup Docker Desktop for Mac or Windows on your local system.
Docker Desktop comes with Docker compose installed by default, hence you don't need to install it separately.
Create an empty file with the below content and save it by name - "docker-compose.yml"
The compose file defines an application with four services
When deploying the application, docker-compose maps port 80 of the web service container to port 80 of the host as specified in the file.
By default, Redis runs on port 6379. Make sure you don't run another instance of Redis on your system or port 6379 on the host is not being used by another container, otherwise the port should be changed.
Let us deploy the full-fledged app using docker-compose:
Listing the running containers. You should see three containers running and the port mapping as below:
After the application starts, navigate to
http://localhost in your web browser or run:
If you want to monitor the Redis keys, you can use the
MONITOR command. Install
redis-cli on your Mac system using
brew install redis and then directly connect to Redis container by issuing the following command: