要使用docker跑sftp的目的
主要是做账户隔离和目录挂载,这样使用起来方便许多,多账户不容易乱
基础镜像
docker hub上顺手搜索一个就行,然后自己打包,主要是自己打包安心一点,本身足够简单的应用没啥难度
https://hub.docker.com/search?q=sftp&type=image
镜像修改
先fork一个镜像: https://github.com/loveyu/docker-sftp
然后调整一下docker file,主要是解决源的更新问题,比如针对debian源,改为使用国内源:
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone \
&& sed -i "s|deb.debian.org/debian|mirrors.tuna.tsinghua.edu.cn/debian|g" /etc/apt/sources.list \
&& sed -i "s|security.debian.org/debian-security|mirrors.tuna.tsinghua.edu.cn/debian-security|g" /etc/apt/sources.list
&& sed -i "s|deb.debian.org/debian|mirrors.tuna.tsinghua.edu.cn/debian|g" /etc/apt/sources.list \
&& sed -i "s|security.debian.org/debian-security|mirrors.tuna.tsinghua.edu.cn/debian-security|g" /etc/apt/sources.list
build 一下
# docker build -t app/sftp:1.0.0 .
[+] Building 11.1s (10/10) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 886B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 34B 0.0s
=> [internal] load metadata for docker.io/library/debian:buster 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 142B 0.0s
=> CACHED [1/5] FROM docker.io/library/debian:buster 0.0s
=> [2/5] RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && sed -i "s|deb.debian.org/debian|mirrors.tuna.tsinghua.edu.cn/debian|g" /etc/apt/sources.list && sed - 10.2s
=> [3/5] COPY files/sshd_config /etc/ssh/sshd_config 0.1s
=> [4/5] COPY files/create-sftp-user /usr/local/bin/ 0.0s
=> [5/5] COPY files/entrypoint / 0.0s
=> exporting to image 0.6s
=> => exporting layers 0.6s
=> => writing image sha256:7143718041e7fd81ac12983ad258cf2daad2c69c93df5c7aa2594a4009e7f532 0.0s
=> => naming to app/sftp:1.0.0
[+] Building 11.1s (10/10) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 886B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 34B 0.0s
=> [internal] load metadata for docker.io/library/debian:buster 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 142B 0.0s
=> CACHED [1/5] FROM docker.io/library/debian:buster 0.0s
=> [2/5] RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && sed -i "s|deb.debian.org/debian|mirrors.tuna.tsinghua.edu.cn/debian|g" /etc/apt/sources.list && sed - 10.2s
=> [3/5] COPY files/sshd_config /etc/ssh/sshd_config 0.1s
=> [4/5] COPY files/create-sftp-user /usr/local/bin/ 0.0s
=> [5/5] COPY files/entrypoint / 0.0s
=> exporting to image 0.6s
=> => exporting layers 0.6s
=> => writing image sha256:7143718041e7fd81ac12983ad258cf2daad2c69c93df5c7aa2594a4009e7f532 0.0s
=> => naming to app/sftp:1.0.0
运行
docker run \
-d \
--restart always \
--name sftp-test \
-v /data/sftp/:/home/test/sftp \
-p 19221:22 -d app/sftp:1.0.0 \
test:123456:1001
-d \
--restart always \
--name sftp-test \
-v /data/sftp/:/home/test/sftp \
-p 19221:22 -d app/sftp:1.0.0 \
test:123456:1001
当前还没有任何评论