Follow these steps to deploy node-express-boilerplate:
Install docker
Prepare 3 hosts
Open protocols and ports between the hosts(Ubuntu). The following ports must be available. On some systems, these ports are open by default.
Port 2377
TCP for communication with and between manager nodes
Port 7946
TCP/UDP for overlay network node discovery
Port 4789
UDP (configurable) for overlay network traffic
sudo iptables -A INPUT -p tcp --dport 2377 -j ACCEPT ; \\
sudo iptables -A INPUT -p tcp --dport 7946 -j ACCEPT ; \\
sudo iptables -A INPUT -p udp --dport 7946 -j ACCEPT ; \\
sudo iptables -A INPUT -p udp --dport 4789 -j ACCEPT
Note: Need all manager1, worker1, worker2 apply this one
docker swarm init
Add nodes to the swarm Connect to these other hosts to add that node to the manager swarm We call these other hosts may be: “worker1”, “worker2” By TOKEN when create swarm
docker swarm join --token <TOKEN> <MANGER_IP>:2377
Clone the repository:
git clone <https://github.com/AnhtuanUit/node-express-boilerplate>
Go to the source code
cd node-express-boilerplate
Set environment variables:
cp .env.example .env
Update .env
with your own environment variables.
Note: make sure you prepare the .env
file before you run the docker scripts because the .env
will be copied to Docker Image the first time run the docker scripts.
Install docker-compose to test the docker-compose.yml file first
All in one command 😛
sudo curl -L "<https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$>(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
Test docker-compose.yml file (for swarm mode deploy stack services)
docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.swarm.yml up
Check that the app is running with docker-compose ps
:
docker-compose ps
You can test the app with curl
:
curl <http://localhost:3000>
curl <http://localhost:27017>
Bring the app down:
docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.swarm.yml down -d
Set up a Docker registry
docker service create --name registry --publish published=5000,target=5000 registry:2