浏览代码

add sample Dockerfiles

Nicola Murino 5 年之前
父节点
当前提交
a7363a16be
共有 4 个文件被更改,包括 91 次插入0 次删除
  1. 5 0
      docker/README.md
  2. 8 0
      docker/rest-api-cli/Dockerfile
  3. 56 0
      docker/sftpgo/debian/Dockerfile
  4. 22 0
      docker/sftpgo/debian/README.md

+ 5 - 0
docker/README.md

@@ -0,0 +1,5 @@
+## Dockerfile examples
+
+Sample Dockerfiles for `sftpgo` daemon and the REST API CLI.
+
+We don't want to add a `Dockerfile` for each single `sftpgo` configuration options or data provider. You can use the docker configurations here as starting point that you can customize to run `sftpgo` with [Docker](http://www.docker.io "Docker").

+ 8 - 0
docker/rest-api-cli/Dockerfile

@@ -0,0 +1,8 @@
+FROM debian:latest
+LABEL maintainer="nicola.murino@gmail.com"
+RUN apt-get update && apt-get install -y curl python3-requests python3-pygments
+
+RUN curl https://raw.githubusercontent.com/drakkan/sftpgo/master/scripts/sftpgo_api_cli.py --output /usr/bin/sftpgo_api_cli.py
+
+ENTRYPOINT ["python3", "/usr/bin/sftpgo_api_cli.py" ]
+CMD []

+ 56 - 0
docker/sftpgo/debian/Dockerfile

@@ -0,0 +1,56 @@
+# we use a multi stage build to have a separate build and run env
+FROM golang:latest as buildenv
+LABEL maintainer="nicola.murino@gmail.com"
+RUN 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 sftpgo 
+
+# now define the run environment
+FROM debian:latest
+
+ARG BASE_DIR=/app
+ARG DATA_REL_DIR=data
+ARG CONFIG_REL_DIR=config
+ARG USERNAME=sftpgo
+ARG GROUPNAME=sftpgo
+ARG UID=515
+ARG GID=515
+
+# HOME_DIR for sftpgo itself
+ENV HOME_DIR=${BASE_DIR}/${USERNAME}
+# DATA_DIR, this is a volume that you can use hold user's home dirs
+ENV DATA_DIR=${BASE_DIR}/${DATA_REL_DIR}
+# CONFIG_DIR, this is a volume to persist the daemon private keys, configuration file ecc.. 
+ENV CONFIG_DIR=${BASE_DIR}/${CONFIG_REL_DIR}
+
+RUN mkdir -p ${DATA_DIR} ${CONFIG_DIR}
+RUN groupadd --system -g ${GID} ${GROUPNAME}
+RUN useradd --system --create-home --no-log-init --home-dir ${HOME_DIR} --comment "SFTPGo user" --shell /bin/false --gid ${GID} --uid ${UID} ${USERNAME}
+
+WORKDIR ${HOME_DIR} 
+RUN mkdir -p bin .config/sftpgo
+ENV PATH ${HOME_DIR}/bin:$PATH
+COPY --from=buildenv /go/src/github.com/drakkan/sftpgo/sftpgo bin/sftpgo 
+# default config file to use if no config file is found inside the CONFIG_DIR volume.
+# You can override each configuration options via env vars too
+COPY --from=buildenv /go/src/github.com/drakkan/sftpgo/sftpgo.json .config/sftpgo/
+RUN chown -R ${UID}:${GID} ${DATA_DIR} 
+
+# run as non root user
+USER ${USERNAME} 
+
+EXPOSE 2022 8080
+
+# the defined volumes must have write access for the UID and GID defined above
+VOLUME [ "$DATA_DIR", "$CONFIG_DIR" ]
+
+# override some default configuration options using env vars
+ENV SFTPGO_CONFIG_DIR=${CONFIG_DIR}
+# setting SFTPGO_LOG_FILE_PATH to an empty string will log to stdout
+ENV SFTPGO_LOG_FILE_PATH=${CONFIG_DIR}/sftpgo.log
+ENV SFTPGO_HTTPD__BIND_ADDRESS=""
+
+ENTRYPOINT ["sftpgo"]
+CMD ["serve"]

+ 22 - 0
docker/sftpgo/debian/README.md

@@ -0,0 +1,22 @@
+## Dockerfile based on Debian stable
+
+Please read the comments inside the `Dockerfile` to learn how to customize things for your setup.
+
+You can build the container image using `docker build`, for example:
+
+```bash
+docker build -t="drakkan/sftpgo" .
+```
+
+and you can run the Dockerfile using something like this:
+
+```bash
+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:
+
+
+```bash
+chown -R <UID>:<GID> /srv/sftpgo/data /srv/sftpgo/config
+```