Skip to content

Instantly share code, notes, and snippets.

@allenyang79
Last active September 23, 2017 04:43
Show Gist options
  • Save allenyang79/5226f2d005100db829275fd1545c3a65 to your computer and use it in GitHub Desktop.
Save allenyang79/5226f2d005100db829275fd1545c3a65 to your computer and use it in GitHub Desktop.

docker stack deploy a multi overlay network with mutli service.

upstream n1_box {
server n1_box:80;
}
upstream n2_box {
server n2_box:80;
}
upstream n3_box {
server n3_box:80;
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
}
location /n1 {
rewrite /n1/(.*) /$1 break;
proxy_set_header host $http_host;
proxy_pass http://n1_box;
}
location /n2 {
rewrite /n2/(.*) /$1 break;
proxy_set_header host $http_host;
proxy_pass http://n2_box;
}
location /n3 {
rewrite /n3/(.*) /$1 break;
proxy_set_header host $http_host;
proxy_pass http://n3_box;
}
}
version: "3.2"
services:
box:
image: nginx:latest
deploy:
placement:
constraints:
- node.hostname == node-1
ports:
- "81:80"
volumes:
- type: bind
source: /vagrant/n1/html
target: /usr/share/nginx/html
networks:
default:
driver: overlay
ipam:
driver: default
config:
- subnet: 172.16.1.0/24
version: "3.2"
services:
box:
image: nginx:latest
deploy:
placement:
constraints:
- node.hostname == node-2
ports:
- "82:80"
volumes:
- type: bind
source: /vagrant/n2/html
target: /usr/share/nginx/html
networks:
default:
driver: overlay
ipam:
driver: default
config:
- subnet: 172.16.2.0/24
version: "3.2"
services:
box:
image: nginx:latest
deploy:
placement:
constraints:
- node.hostname == node-3
ports:
- "83:80"
volumes:
- type: bind
source: /vagrant/n3/html
target: /usr/share/nginx/html
networks:
overlay:
driver: overlay
ipam:
driver: default
config:
- subnet: 172.16.0.0/16
version: "3.2"
services:
box:
image: nginx:latest
deploy:
placement:
constraints:
- node.hostname == node-1
ports:
- "80:80"
volumes:
- type: bind
source: /vagrant/proxy/conf.d
target: /etc/nginx/conf.d
- type: bind
source: /vagrant/proxy/html
target: /usr/share/nginx/html
networks:
- default
- n1_default
- n2_default
- n3_default
networks:
n1_default:
external:
name: n1_default
n2_default:
external:
name: n2_default
n3_default:
external:
name: n3_default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment