mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-07 14:50:55 +03:00
docker: minor fixes
This commit is contained in:
@@ -1,22 +1,23 @@
|
|||||||
FROM golang:1.13-alpine3.10 as builder
|
FROM golang:1.13-alpine3.10 as builder
|
||||||
|
|
||||||
RUN apk add --no-cache git gcc g++ ca-certificates \
|
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
|
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
|
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
|
FROM alpine:3.10
|
||||||
|
|
||||||
RUN apk add --no-cache ca-certificates su-exec \
|
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/bin/sftpgo /bin/
|
||||||
COPY --from=builder /go/src/github.com/drakkan/sftpgo/sftpgo.json /etc/sftpgo/sftpgo.json
|
COPY --from=builder /go/src/github.com/drakkan/sftpgo/sftpgo.json /etc/sftpgo/sftpgo.json
|
||||||
COPY docker-entrypoint.sh /bin/entrypoint.sh
|
COPY docker-entrypoint.sh /bin/entrypoint.sh
|
||||||
RUN chmod +x /bin/entrypoint.sh
|
RUN chmod +x /bin/entrypoint.sh
|
||||||
|
|
||||||
VOLUME /data
|
VOLUME [ "/data", "/srv/sftpgo/config" ]
|
||||||
EXPOSE 2022 8080
|
EXPOSE 2022 8080
|
||||||
|
|
||||||
ENTRYPOINT ["/bin/entrypoint.sh"]
|
ENTRYPOINT ["/bin/entrypoint.sh"]
|
||||||
|
|||||||
@@ -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.
|
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
|
### Example
|
||||||
> 1003 is a custom uid:gid for this instance of SFTPgo
|
> 1003 is a custom uid:gid for this instance of SFTPgo
|
||||||
```
|
```bash
|
||||||
# Prereq on docker host
|
# Prereq on docker host
|
||||||
sudo groupadd -g 1003 sftpgrp && \
|
sudo groupadd -g 1003 sftpgrp && \
|
||||||
sudo useradd -u 1003 -g 1003 sftpuser -d /home/sftpuser/ && \
|
sudo useradd -u 1003 -g 1003 sftpuser -d /home/sftpuser/ && \
|
||||||
sudo -u sftpuser mkdir /home/sftpuser/{conf,data} && \
|
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/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
|
# Get and build SFTPgo image
|
||||||
git clone https://github.com/drakkan/sftpgo.git && \
|
git clone https://github.com/drakkan/sftpgo.git && \
|
||||||
cd sftpgo && \
|
cd sftpgo && \
|
||||||
sudo docker build -t sftpgo docker/alpine/
|
sudo docker build -t sftpgo docker/sftpgo/alpine/
|
||||||
|
|
||||||
# Starting image
|
# Starting image
|
||||||
sudo docker run --name sftpgo \
|
sudo docker run --name sftpgo \
|
||||||
-e SFTPGO_LOG_FILE_PATH= \
|
-e SFTPGO_LOG_FILE_PATH= \
|
||||||
-e SFTPGO_CONFIG_DIR=/etc/sftpgo \
|
-e SFTPGO_CONFIG_DIR=/srv/sftpgo/config \
|
||||||
-p 8080:8080 \
|
-p 8080:8080 \
|
||||||
-p 2022:2022 \
|
-p 2022:2022 \
|
||||||
-e PUID=1003 \
|
-e PUID=1003 \
|
||||||
-e GUID=1003 \
|
-e GUID=1003 \
|
||||||
-v /home/sftpuser/conf/:/etc/sftpgo/ \
|
-v /home/sftpuser/conf/:/srv/sftpgo/config \
|
||||||
-v /home/sftpuser/data:/data \
|
-v /home/sftpuser/data:/data \
|
||||||
sftpgo
|
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.
|
Several images can be run with another parameters.
|
||||||
|
|
||||||
### Custom systemD script
|
### Custom systemd script
|
||||||
An example of systemD script is present [here](../../init/sftpgo-docker.service), with `Environment` parameter to set `PUID` and `GUID`
|
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.
|
`WorkingDirectory` parameter must be exist with one file in this directory like `sftpgo-${PUID}.env` corresponding to the variable file for SFTPgo instance.
|
||||||
|
|
||||||
Enjoy
|
Enjoy
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
chown -R "${PUID}:${GUID}" /data /etc/sftpgo \
|
chown -R "${PUID}:${GUID}" /data /etc/sftpgo /srv/sftpgo/config \
|
||||||
&& exec su-exec "${PUID}:${GUID}" \
|
&& exec su-exec "${PUID}:${GUID}" \
|
||||||
/bin/sftpgo serve "$@"
|
/bin/sftpgo serve "$@"
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ ExecStart=docker run --name sftpgo \
|
|||||||
-e GUID=${GUID} \
|
-e GUID=${GUID} \
|
||||||
-p 8080:8080 \
|
-p 8080:8080 \
|
||||||
-p 2022:2022 \
|
-p 2022:2022 \
|
||||||
-v /home/sftpuser/conf/:/etc/sftpgo/ \
|
-v /home/sftpuser/conf/:/srv/sftpgo/config \
|
||||||
-v /home/sftpuser/data:/data \
|
-v /home/sftpuser/data:/data \
|
||||||
sftpgo
|
sftpgo
|
||||||
ExecStop=docker stop sftpgo
|
ExecStop=docker stop sftpgo
|
||||||
|
|||||||
@@ -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
|
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
|
```bash
|
||||||
|
|||||||
@@ -301,10 +301,10 @@ func (c Configuration) handleSftpConnection(channel io.ReadWriteCloser, connecti
|
|||||||
server := sftp.NewRequestServer(channel, handler)
|
server := sftp.NewRequestServer(channel, handler)
|
||||||
|
|
||||||
if err := server.Serve(); err == io.EOF {
|
if err := server.Serve(); err == io.EOF {
|
||||||
connection.Log(logger.LevelDebug, logSenderSCP, "connection closed")
|
connection.Log(logger.LevelDebug, logSender, "connection closed")
|
||||||
server.Close()
|
server.Close()
|
||||||
} else if err != nil {
|
} 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)
|
removeConnection(connection.ID)
|
||||||
|
|||||||
Reference in New Issue
Block a user