This lab creates a high availability architecture using docker swarm :
a simple Go service that communicates with MongoDB.
- Clone this repository
$ git clone https://github.com/Nezz7/docker-swarm-lab.git
- Change the current working directory
$ cd /docker-swarm-lab
- Create the docker image : server-image
$ docker build -t server-image .
- Initialize the swarm
$ docker swarm init
Don't forget to save the token. - Deploy the stack to the swarm
$ docker stack deploy --compose-file docker-compose.yml $SERVICE_NAME
- Check that it’s running
$ docker stack services $SERVICE_NAME
Service | Exposed Pot | Internal Port |
---|---|---|
Server | 8080 | 8080 |
MongoDB | - | 27017 |
Get all users
http://$SERVER_IP:8080/api/users
Example of response :
[
{
"_id": "5fd6314d6dfce4826add769d",
"age": 18,
"name": "nezz"
}
]
Post a user
http://$SERVER_IP:8080/api/user
Example of Body :
{
"name": "nezz",
"age": 18
}