mirror of
https://github.com/drakkan/sftpgo.git
synced 2024-11-25 00:50:31 +00:00
Docker alpine multiuser (#39)
* SFTPgo with docker alpine image and init systemD * Permissions entrypoint script + ENTRYPOINT directive * Drakkan's reviewed fix Move Dockerfile into docker/sftpgo/ * Add Default Configuration File in image Add -R to chown default config file in the directory Move systemD init file for the alpine image
This commit is contained in:
parent
4f1c2c094f
commit
29f69876fe
4 changed files with 104 additions and 0 deletions
23
docker/sftpgo/alpine/Dockerfile
Normal file
23
docker/sftpgo/alpine/Dockerfile
Normal file
|
@ -0,0 +1,23 @@
|
|||
FROM golang:1.13-alpine3.10 as builder
|
||||
|
||||
RUN apk add --no-cache git gcc g++ ca-certificates \
|
||||
&& go get -u github.com/drakkan/sftpgo
|
||||
WORKDIR /go/src/github.com/drakkan/sftpgo
|
||||
|
||||
RUN go build -i -ldflags "-s -w -X github.com/drakkan/sftpgo/utils.commit=`git describe --always --dirty` -X github.com/drakkan/sftpgo/utils.date=`date -u +%FT%TZ`" -o /go/bin/sftpgo
|
||||
|
||||
FROM alpine:3.10
|
||||
|
||||
RUN apk add --no-cache ca-certificates su-exec \
|
||||
&& mkdir -p /data /etc/sftpgo
|
||||
|
||||
COPY --from=builder /go/bin/sftpgo /bin/
|
||||
COPY --from=builder /go/src/github.com/drakkan/sftpgo/sftpgo.json /etc/sftpgo/sftpgo.json
|
||||
COPY docker-entrypoint.sh /bin/entrypoint.sh
|
||||
RUN chmod +x /bin/entrypoint.sh
|
||||
|
||||
VOLUME /data
|
||||
EXPOSE 2022 8080
|
||||
|
||||
ENTRYPOINT ["/bin/entrypoint.sh"]
|
||||
CMD []
|
45
docker/sftpgo/alpine/README.md
Normal file
45
docker/sftpgo/alpine/README.md
Normal file
|
@ -0,0 +1,45 @@
|
|||
# SFTPgo with Docker and Alpine
|
||||
|
||||
This DockerFile is made to build image to host multiple instances of SFTPgo started with different users.
|
||||
|
||||
The volume for the configuration is not mandatory, but it will be necessary to configure SFTPgo with environment variables.
|
||||
|
||||
### Example
|
||||
> 1003 is a custom uid:gid for this instance of SFTPgo
|
||||
```
|
||||
# Prereq on docker host
|
||||
sudo groupadd -g 1003 sftpgrp && \
|
||||
sudo useradd -u 1003 -g 1003 sftpuser -d /home/sftpuser/ && \
|
||||
sudo -u sftpuser mkdir /home/sftpuser/{conf,data} && \
|
||||
curl https://raw.githubusercontent.com/drakkan/sftpgo/master/sql/sqlite/20190828.sql | sqlite3 /home/sftpuser/conf/sftpgo.db && \
|
||||
curl https://raw.githubusercontent.com/drakkan/sftpgo/master/sftpgo.json -o /home/sftpuser/conf/sftpgo.conf
|
||||
|
||||
# Get and build SFTPgo image
|
||||
git clone https://github.com/drakkan/sftpgo.git && \
|
||||
cd sftpgo && \
|
||||
sudo docker build -t sftpgo docker/alpine/
|
||||
|
||||
# Starting image
|
||||
sudo docker run --name sftpgo \
|
||||
-e SFTPGO_LOG_FILE_PATH= \
|
||||
-e SFTPGO_CONFIG_DIR=/etc/sftpgo \
|
||||
-p 8080:8080 \
|
||||
-p 2022:2022 \
|
||||
-e PUID=1003 \
|
||||
-e GUID=1003 \
|
||||
-v /home/sftpuser/conf/:/etc/sftpgo/ \
|
||||
-v /home/sftpuser/data:/data \
|
||||
sftpgo
|
||||
```
|
||||
The script `entrypoint.sh` makes sure to correct the permissions of directories and start the process with the right user
|
||||
|
||||
Several images can be run with another parameters.
|
||||
|
||||
### Custom systemD script
|
||||
An example of systemD script is present [here](../../init/sftpgo-docker.service), with `Environment` parameter to set `PUID` and `GUID`
|
||||
|
||||
`WorkingDirectory` parameter must be exist with one file in this directory like `sftpgo-${PUID}.env` corresponding to the variable file for SFTPgo instance.
|
||||
|
||||
Enjoy
|
||||
|
||||
|
7
docker/sftpgo/alpine/docker-entrypoint.sh
Executable file
7
docker/sftpgo/alpine/docker-entrypoint.sh
Executable file
|
@ -0,0 +1,7 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
chown -R "${PUID}:${GUID}" /data /etc/sftpgo \
|
||||
&& exec su-exec "${PUID}:${GUID}" \
|
||||
/bin/sftpgo serve "$@"
|
29
docker/sftpgo/alpine/sftpgo.service
Normal file
29
docker/sftpgo/alpine/sftpgo.service
Normal file
|
@ -0,0 +1,29 @@
|
|||
[Unit]
|
||||
Description=SFTPGo sftp server
|
||||
After=docker.service
|
||||
|
||||
[Service]
|
||||
User=root
|
||||
Group=root
|
||||
WorkingDirectory=/etc/sftpgo
|
||||
Environment=PUID=1003
|
||||
Environment=GUID=1003
|
||||
EnvironmentFile=-/etc/sysconfig/sftpgo.conf
|
||||
ExecStartPre=-docker kill sftpgo
|
||||
ExecStartPre=-docker rm sftpgo
|
||||
ExecStart=docker run --name sftpgo \
|
||||
--env-file sftpgo-${PUID}.env \
|
||||
-e PUID=${PUID} \
|
||||
-e GUID=${GUID} \
|
||||
-p 8080:8080 \
|
||||
-p 2022:2022 \
|
||||
-v /home/sftpuser/conf/:/etc/sftpgo/ \
|
||||
-v /home/sftpuser/data:/data \
|
||||
sftpgo
|
||||
ExecStop=docker stop sftpgo
|
||||
SyslogIdentifier=sftpgo
|
||||
Restart=always
|
||||
RestartSec=10s
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Loading…
Reference in a new issue