Skip to content

Commit 5b5033d

Browse files
author
shvetsovdm
committed
Add the example code
0 parents  commit 5b5033d

File tree

9 files changed

+115
-0
lines changed

9 files changed

+115
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

docker-compose.yml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
version: '3'
2+
3+
services:
4+
nginx-proxy:
5+
image: jwilder/nginx-proxy
6+
ports:
7+
- 8080:80
8+
volumes:
9+
- /var/run/docker.sock:/tmp/docker.sock:ro
10+
11+
weba:
12+
build:
13+
context: web/a
14+
expose:
15+
- 8081
16+
environment:
17+
- VIRTUAL_HOST=a.localhost
18+
depends_on:
19+
- nginx-proxy
20+
webb:
21+
build:
22+
context: web/b
23+
expose:
24+
- 8082
25+
environment:
26+
- VIRTUAL_HOST=b.localhost
27+
depends_on:
28+
- nginx-proxy
29+
webc:
30+
build:
31+
context: web/generic
32+
expose:
33+
- 8080
34+
environment:
35+
- VIRTUAL_HOST=c.localhost
36+
- WEB_MESSAGE=Web C from generic
37+
- WEB_NAME=D
38+
- WEB_PORT=8080
39+
depends_on:
40+
- nginx-proxy
41+
webd:
42+
build:
43+
context: web/generic
44+
expose:
45+
- 8080
46+
environment:
47+
- VIRTUAL_HOST=d.localhost
48+
- WEB_MESSAGE=Web D from generic
49+
- WEB_NAME=D
50+
- WEB_PORT=8080
51+
depends_on:
52+
- nginx-proxy

readme.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Docker nginx-proxy example
2+
3+
nginx-proxy sets up a container running nginx and docker-gen. docker-gen generates reverse proxy configs for nginx and reloads nginx when containers are started and stopped.
4+
5+
See Automated Nginx Reverse Proxy for Docker for why you might want to use this.
6+
7+
[source](https://github.com/jwilder/nginx-proxy)
8+
9+
## Run
10+
11+
In order to run example execute in root of the cloned repo:
12+
13+
$ docker-compose up
14+
15+
It will run 4 node.js HTTP servers [a.localhost:8080](http://a.localhost:8080), [b.localhost:8080](http://b.localhost:8080), [c.localhost:8080](http://c.localhost:8080), [d.localhost:8080](http://d.localhost:8080). The servers responds with plain text.

web/a/Dockerfile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM mhart/alpine-node:8.11
2+
3+
WORKDIR /app
4+
COPY /app .
5+
6+
EXPOSE 8081
7+
8+
CMD ["node", "index.js"]

web/a/app/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const http = require('http');
2+
3+
function requestHandler(req, res) {
4+
res.end('Web A');
5+
}
6+
7+
const httpServer = http.createServer((req, res) => requestHandler(req, res));
8+
httpServer.listen(8081, () => console.log('Web A is running on 8081'));

web/b/Dockerfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM mhart/alpine-node:8.11
2+
3+
COPY app .
4+
5+
CMD ["node", "index.js"]

web/b/app/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const http = require('http');
2+
3+
function requestHandler(req, res) {
4+
res.end('Web B');
5+
}
6+
7+
const httpServer = http.createServer((req, res) => requestHandler(req, res));
8+
httpServer.listen(8082, () => console.log('Web B is runnong on 8082'));

web/generic/Dockerfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM mhart/alpine-node:8.11
2+
3+
WORKDIR /app
4+
5+
COPY app .
6+
7+
CMD ["node", "index.js"]

web/generic/app/index.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const http = require('http');
2+
const msg = process.env.WEB_MESSAGE;
3+
const name = process.env.WEB_NAME;
4+
const port = process.env.WEB_PORT;
5+
6+
function requestHandler(req, res) {
7+
res.end(msg);
8+
}
9+
10+
const httpServer = http.createServer((req, res) => requestHandler(req, res));
11+
httpServer.listen(port, () => console.log(`Web ${name} is running on ${port}`));

0 commit comments

Comments
 (0)