Skip to content

Commit 3e8a1c2

Browse files
committed
Added docker swarm support, updated README
1 parent 1d491ab commit 3e8a1c2

File tree

3 files changed

+44
-10
lines changed

3 files changed

+44
-10
lines changed

Diff for: Dockerfile

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM centurylink/openssl as keys
1+
FROM nginx:alpine
2+
RUN apk add --no-cache openssl
23
RUN echo $'[req] \n\
34
distinguished_name = req_distinguished_name \n\
45
x509_extensions = v3_req \n\
@@ -12,9 +13,9 @@ subjectAltName = @alt_names \n\
1213
[alt_names] \n\
1314
DNS.1 = *.localhost \n\
1415
DNS.2 = localhost' > openssl.cnf
15-
RUN openssl req -new -newkey rsa:2048 -sha1 -days 3650 -nodes -x509 -keyout cert.key -out cert.crt -config openssl.cnf
16-
17-
FROM nginx:alpine
16+
RUN mkdir -p /run/secrets/
17+
RUN openssl req -new -newkey rsa:2048 -sha1 -days 3650 -nodes -x509 -keyout /run/secrets/cert.key -out /run/secrets/cert.crt -config openssl.cnf
1818
COPY . /etc/nginx/
19-
COPY --from=keys cert.key /run/secrets/cert.key
20-
COPY --from=keys cert.crt /run/secrets/cert.crt
19+
RUN ln -sf /dev/stdout /var/log/nginx/bots.access.log
20+
RUN rm openssl.cnf
21+
RUN apk del openssl

Diff for: README.md

+36-3
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ Awesome Nginx configuration template and a set of handy must-have snippets.
1414
* Various predefined locations
1515
* Advanced logging
1616
* SEO
17-
* Docker-ready
17+
* Docker/Swarm ready
1818

1919
## Requirements
20-
* Docker
21-
* docker-compose
20+
* `Docker` >= `1.13`
21+
* `docker-compose` >= `3.1`
2222

2323
Configs themselves depend on `Nginx` >= `1.9.5`, if used separately.
2424

@@ -52,10 +52,43 @@ $ docker-compose exec nginx nginx -s reload
5252
### Logs
5353
By default a new `logs/` directory should be created in the project directory, that directly maps to the nginx logs directory.
5454

55+
#### Docker swarm
56+
To run in Docker swarm first make sure your Docker setup is in swarm mode:
57+
58+
```bash
59+
$ docker swarm init
60+
```
61+
62+
First of all you need to define your domain ssl certificate and key as a swarm secret:
63+
64+
```bash
65+
$ docker secret create cert.crt your_certificate.crt
66+
$ docker secret create cert.key your_certificate_key.key
67+
```
68+
69+
Now to start or update nginx (and php) services in the swarm run:
70+
71+
```bash
72+
$ docker stack deploy -c docker-compose.yml --with-registry-auth --prune app
73+
```
74+
75+
To see nginx logs run:
76+
```bash
77+
$ docker service logs -f app_nginx
78+
```
79+
80+
To scale services:
81+
```bash
82+
$ docker service scale app_nginx=2 app_fpm=10
83+
```
84+
85+
Now you can refresh the page a couple of times and notice different host names that your requests land on.
5586

5687
### Customization
5788

5889
The main virtual host definition is located at `servers/main.conf`.
90+
Probably the best way to work with the repo is by cloning it and hooking up docker hub to automatically build a new image whenever there's new code.
91+
5992

6093
## If something doesn't work
6194
* Check error and access logs

Diff for: docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: '3.1'
22
services:
33
nginx:
4-
hostname: ${HOST_NAME:-localhost}
4+
hostname: localhost
55
image: umkus/nginx-boilerplate
66
ports:
77
- 80:80

0 commit comments

Comments
 (0)