Browse Source

Merge pull request #2753 from JohnTheNerd/password-file

added support for Docker secrets and password file in the Docker image
pull/2759/head
Max Lv 4 years ago
committed by GitHub
parent
commit
8be4f19758
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 9 deletions
  1. 12
      docker/alpine/Dockerfile
  2. 26
      docker/alpine/README.md
  3. 19
      docker/alpine/entrypoint.sh

12
docker/alpine/Dockerfile

@ -48,12 +48,6 @@ RUN set -ex \
USER nobody
CMD exec ss-server \
-s $SERVER_ADDR \
-p $SERVER_PORT \
-k ${PASSWORD:-$(hostname)} \
-m $METHOD \
-t $TIMEOUT \
-d $DNS_ADDRS \
-u \
$ARGS
COPY ./docker/alpine/entrypoint.sh /entrypoint.sh
CMD /entrypoint.sh

26
docker/alpine/README.md

@ -56,6 +56,32 @@ $ docker run -e PASSWORD=9MLSpPmNt -p 8388:8388 -p 8388:8388/udp -d --restart al
```
> :warning: Click [here][6] to generate a strong password to protect your server.
### With password as a mounted file or a Docker secret (swarm only)
Instead of hardcoding a password to the docker-compose file or `docker run` command, you can mount in a file that contains the password. To do so, pass the path that you mounted to the container as the `PASSWORD_FILE` environment variable.
If you are running Docker Swarm, you can also utilize Docker secrets. To do so, pass the name of the secret as the `PASSWORD_SECRET` environment variable. If you specify both `PASSWORD_FILE` and `PASSWORD_SECRET`, the latter will take effect.
This is a sample `docker-compose.yml` file that uses the external Docker secret named `shadowsocks` as the password.
```yaml
shadowsocks:
image: shadowsocks/shadowsocks-libev
ports:
- "8388:8388"
environment:
- METHOD=aes-256-gcm
- PASSWORD_SECRET=shadowsocks
secrets:
- shadowsocks
```
This is a sample `docker service create` command that uses the external Docker secret named `shadowsocks` as the password.
```bash
docker service create -e PASSWORD_SECRET=shadowsocks -p 8388:8388 -p 8388:8388/udp --secret shadowsocks shadowsocks/shadowsocks-libev
```
### With other customizations
Besides `PASSWORD`, the image also defines the following environment variables that you can customize:
* `SERVER_ADDR`: the IP/domain to bind to, defaults to `0.0.0.0`

19
docker/alpine/entrypoint.sh

@ -0,0 +1,19 @@
#!/bin/sh
if [[ -f "$PASSWORD_FILE" ]]; then
PASSWORD=$(cat "$PASSWORD_FILE")
fi
if [[ -f "/var/run/secrets/$PASSWORD_SECRET" ]]; then
PASSWORD=$(cat "/var/run/secrets/$PASSWORD_SECRET")
fi
exec ss-server \
-s $SERVER_ADDR \
-p $SERVER_PORT \
-k ${PASSWORD:-$(hostname)} \
-m $METHOD \
-t $TIMEOUT \
-d $DNS_ADDRS \
-u \
$ARGS
Loading…
Cancel
Save