NATS is a messaging system for exchanging information between applications by sending and receiving messages. NATS is an open-source project written in Go programming language.
This tutorial explains how to install NATS inside a Docker container in the Linux. Commands have been tested on Ubuntu.
Prepare environment
Make sure you have installed Docker in your system. If you are using Ubuntu, installation instructions can be found in the post.
Install NATS
- Host network
Run the following command to create a container for NATS that uses host network:
docker run -d --name=nats --restart=always --network=host nats
- User-defined bridge network
User-defined bridge network can be used for listening on different port. By default, NATS service is listening for client connections on port 4222 and also listening on port 6222 that used for clustering. Information management UI is available on port 8222. Ports can be changed with -p
option.
docker network create app-net
docker run -d --name=nats --restart=always --network=app-net \
-p 8080:4222 -p 8081:6222 -p 8082:8222 \
nats
Testing NATS
To access information management UI, open a web browser and go to http://<IP_ADDRESS>:8222
, where <IP_ADDRESS>
is the IP address of the system.
Uninstall NATS
To completely remove NATS, remove its container:
docker rm --force nats
Remove NATS image:
docker rmi nats
If a user-defined bridge network was created, you can delete it as follows:
docker network rm app-net
Leave a Comment
Cancel reply