docker: minor fixes

This commit is contained in:
Nicola Murino
2019-09-07 18:21:03 +02:00
parent 29f69876fe
commit 2a7e56ed29
7 changed files with 27 additions and 28 deletions

View File

@@ -1,22 +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
&& go get -d github.com/drakkan/sftpgo
WORKDIR /go/src/github.com/drakkan/sftpgo
# uncomment the next line to get the latest stable version instead of the latest git
#RUN git checkout `git rev-list --tags --max-count=1`
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
&& mkdir -p /data /etc/sftpgo /srv/sftpgo/config
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
VOLUME [ "/data", "/srv/sftpgo/config" ]
EXPOSE 2022 8080
ENTRYPOINT ["/bin/entrypoint.sh"]

View File

@@ -1,4 +1,4 @@
# SFTPgo with Docker and Alpine
# SFTPGo with Docker and Alpine
This DockerFile is made to build image to host multiple instances of SFTPgo started with different users.
@@ -6,28 +6,28 @@ The volume for the configuration is not mandatory, but it will be necessary to c
### Example
> 1003 is a custom uid:gid for this instance of SFTPgo
```
```bash
# 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
curl https://raw.githubusercontent.com/drakkan/sftpgo/master/sftpgo.json -o /home/sftpuser/conf/sftpgo.json
# Get and build SFTPgo image
git clone https://github.com/drakkan/sftpgo.git && \
cd sftpgo && \
sudo docker build -t sftpgo docker/alpine/
sudo docker build -t sftpgo docker/sftpgo/alpine/
# Starting image
sudo docker run --name sftpgo \
-e SFTPGO_LOG_FILE_PATH= \
-e SFTPGO_CONFIG_DIR=/etc/sftpgo \
-e SFTPGO_CONFIG_DIR=/srv/sftpgo/config \
-p 8080:8080 \
-p 2022:2022 \
-e PUID=1003 \
-e GUID=1003 \
-v /home/sftpuser/conf/:/etc/sftpgo/ \
-v /home/sftpuser/conf/:/srv/sftpgo/config \
-v /home/sftpuser/data:/data \
sftpgo
```
@@ -35,11 +35,9 @@ The script `entrypoint.sh` makes sure to correct the permissions of directories
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`
### Custom systemd script
An example of systemd script is present [here](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

View File

@@ -2,6 +2,6 @@
set -eu
chown -R "${PUID}:${GUID}" /data /etc/sftpgo \
chown -R "${PUID}:${GUID}" /data /etc/sftpgo /srv/sftpgo/config \
&& exec su-exec "${PUID}:${GUID}" \
/bin/sftpgo serve "$@"

View File

@@ -17,7 +17,7 @@ ExecStart=docker run --name sftpgo \
-e GUID=${GUID} \
-p 8080:8080 \
-p 2022:2022 \
-v /home/sftpuser/conf/:/etc/sftpgo/ \
-v /home/sftpuser/conf/:/srv/sftpgo/config \
-v /home/sftpuser/data:/data \
sftpgo
ExecStop=docker stop sftpgo

View File

@@ -14,7 +14,7 @@ and you can run the Dockerfile using something like this:
docker run --name sftpgo -p 8080:8080 -p 2022:2022 --mount type=bind,source=/srv/sftpgo/data,target=/app/data --mount type=bind,source=/srv/sftpgo/config,target=/app/config drakkan/sftpgo
```
where `/srv/sftpgo/data` and `/srv/sftpgo/config` are two folders on the host system with write access for UID/GID defined inside the `Dockerfile`. You can choose to create a new user with a matching UID/GID pair or simply do something like:
where `/srv/sftpgo/data` and `/srv/sftpgo/config` are two folders on the host system with write access for UID/GID defined inside the `Dockerfile`. You can choose to create a new user, on the host system, with a matching UID/GID pair or simply do something like:
```bash

View File

@@ -301,10 +301,10 @@ func (c Configuration) handleSftpConnection(channel io.ReadWriteCloser, connecti
server := sftp.NewRequestServer(channel, handler)
if err := server.Serve(); err == io.EOF {
connection.Log(logger.LevelDebug, logSenderSCP, "connection closed")
connection.Log(logger.LevelDebug, logSender, "connection closed")
server.Close()
} else if err != nil {
connection.Log(logger.LevelError, logSenderSCP, "sftp connection closed with error: %v", err)
connection.Log(logger.LevelWarn, logSender, "connection closed with error: %v", err)
}
removeConnection(connection.ID)