Skip to content

Commit 5ff07fa

Browse files
authored
Merge pull request #872 from ahgraber/master
Add Docker secrets
2 parents 272c652 + 3964bbf commit 5ff07fa

File tree

5 files changed

+98
-4
lines changed

5 files changed

+98
-4
lines changed

docker/Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ ARG BUILD_DATE
1313

1414
ENV SUPPRESS_NO_CONFIG_WARNING=1
1515
ENV S6_FIX_ATTRS_HIDDEN=1
16+
ENV S6_BEHAVIOUR_IF_STAGE2_FAILS=1
1617
ENV NODE_ENV=production
1718

1819
RUN echo "fs.file-max = 65535" > /etc/sysctl.conf \
@@ -31,18 +32,20 @@ EXPOSE 80
3132
EXPOSE 81
3233
EXPOSE 443
3334

34-
COPY docker/rootfs /
3535
ADD backend /app
3636
ADD frontend/dist /app/frontend
3737
COPY global /app/global
3838

3939
WORKDIR /app
4040
RUN yarn install
4141

42+
# add late to limit cache-busting by modifications
43+
COPY docker/rootfs /
44+
4245
# Remove frontend service not required for prod, dev nginx config as well
4346
RUN rm -rf /etc/services.d/frontend RUN rm -f /etc/nginx/conf.d/dev.conf
4447

4548
VOLUME [ "/data", "/etc/letsencrypt" ]
46-
CMD [ "/init" ]
49+
ENTRYPOINT [ "/init" ]
4750

4851
HEALTHCHECK --interval=5s --timeout=3s CMD /bin/check-health

docker/dev/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ EXPOSE 80
2727
EXPOSE 81
2828
EXPOSE 443
2929

30-
CMD [ "/init" ]
30+
ENTRYPOINT [ "/init" ]
3131

32-
HEALTHCHECK --interval=5s --timeout=3s CMD /bin/check-health
32+
HEALTHCHECK --interval=5s --timeout=3s CMD /bin/check-health
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*
22
!.gitignore
3+
!*.sh
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/with-contenv bash
2+
# ref: https://github.com/linuxserver/docker-baseimage-alpine/blob/master/root/etc/cont-init.d/01-envfile
3+
4+
# in s6, environmental variables are written as text files for s6 to monitor
5+
# seach through full-path filenames for files ending in "__FILE"
6+
for FILENAME in $(find /var/run/s6/container_environment/ | grep "__FILE$"); do
7+
echo "[secret-init] Evaluating ${FILENAME##*/} ..."
8+
9+
# set SECRETFILE to the contents of the full-path textfile
10+
SECRETFILE=$(cat ${FILENAME})
11+
# SECRETFILE=${FILENAME}
12+
# echo "[secret-init] Set SECRETFILE to ${SECRETFILE}" # DEBUG - rm for prod!
13+
14+
# if SECRETFILE exists / is not null
15+
if [[ -f ${SECRETFILE} ]]; then
16+
# strip the appended "__FILE" from environmental variable name ...
17+
STRIPFILE=$(echo ${FILENAME} | sed "s/__FILE//g")
18+
# echo "[secret-init] Set STRIPFILE to ${STRIPFILE}" # DEBUG - rm for prod!
19+
20+
# ... and set value to contents of secretfile
21+
# since s6 uses text files, this is effectively "export ..."
22+
printf $(cat ${SECRETFILE}) > ${STRIPFILE}
23+
# echo "[secret-init] Set ${STRIPFILE##*/} to $(cat ${STRIPFILE})" # DEBUG - rm for prod!"
24+
echo "[secret-init] Success! ${STRIPFILE##*/} set from ${FILENAME##*/}"
25+
26+
else
27+
echo "[secret-init] cannot find secret in ${FILENAME}"
28+
fi
29+
done

docs/advanced-config/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,66 @@
11
# Advanced Configuration
22

3+
## Docker Secrets
4+
5+
This image supports the use of Docker secrets to import from file and keep sensitive usernames or passwords from being passed or preserved in plaintext.
6+
7+
You can set any environment variable from a file by appending `__FILE` (double-underscore FILE) to the environmental variable name.
8+
9+
```yml
10+
version: "3.7"
11+
12+
secrets:
13+
# Secrets are single-line text files where the sole content is the secret
14+
# Paths in this example assume that secrets are kept in local folder called ".secrets"
15+
DB_ROOT_PWD:
16+
file: .secrets/db_root_pwd.txt
17+
MYSQL_PWD:
18+
file: .secrets/mysql_pwd.txt
19+
20+
services:
21+
app:
22+
image: 'jc21/nginx-proxy-manager:latest'
23+
restart: always
24+
ports:
25+
# Public HTTP Port:
26+
- '80:80'
27+
# Public HTTPS Port:
28+
- '443:443'
29+
# Admin Web Port:
30+
- '81:81'
31+
environment:
32+
# These are the settings to access your db
33+
DB_MYSQL_HOST: "db"
34+
DB_MYSQL_PORT: 3306
35+
DB_MYSQL_USER: "npm"
36+
# DB_MYSQL_PASSWORD: "npm" # use secret instead
37+
DB_MYSQL_PASSWORD__FILE: /run/secrets/MYSQL_PWD
38+
DB_MYSQL_NAME: "npm"
39+
# If you would rather use Sqlite uncomment this
40+
# and remove all DB_MYSQL_* lines above
41+
# DB_SQLITE_FILE: "/data/database.sqlite"
42+
# Uncomment this if IPv6 is not enabled on your host
43+
# DISABLE_IPV6: 'true'
44+
volumes:
45+
- ./data:/data
46+
- ./letsencrypt:/etc/letsencrypt
47+
depends_on:
48+
- db
49+
db:
50+
image: jc21/mariadb-aria
51+
restart: always
52+
environment:
53+
# MYSQL_ROOT_PASSWORD: "npm" # use secret instead
54+
MYSQL_ROOT_PASSWORD__FILE: /run/secrets/DB_ROOT_PWD
55+
MYSQL_DATABASE: "npm"
56+
MYSQL_USER: "npm"
57+
# MYSQL_PASSWORD: "npm" # use secret instead
58+
MYSQL_PASSWORD__FILE: /run/secrets/MYSQL_PWD
59+
volumes:
60+
- ./data/mysql:/var/lib/mysql
61+
```
62+
63+
364
## Disabling IPv6
465
566
On some docker hosts IPv6 may not be enabled. In these cases, the following message may be seen in the log:

0 commit comments

Comments
 (0)