docker部署sftp
一. 按照我博客中搭建sftp的方法做一个docker镜像
这种方法可用,但不是最好的,待改进。可参照另一篇博客:设置多用户不同权限的sftp服务器搭建
1. dockerfile文件如下,当前目录假定为sftp_docker

FROM ubuntu:14.04
ADD ./source.list /etc/apt/sources.list #这个是阿里云的源文件,放置在当前目录下
#设置ssh,使容器可SSH连接,经测试下面的2步都是必须的,否则会出错,虽然不太清楚为什么...
RUN apt-get update
RUN apt-get -y install openssh-server
RUN mkdir /var/run/sshd
RUN /bin/sed -i 's/.*session.*required.*pam_loginuid.so.*/session optional pam_loginuid.so/g' /etc/pam.d/sshd
#下面的命令就是参照上面的文字说明一步步写了
RUN groupadd sftp
RUN useradd -g sftp -s /bin/false mysftp
RUN echo "mysftp:123" | chpasswd \n
RUN mkdir -p /data/sftp/mysftp
RUN usermod -d /data/sftp/mysftp mysftp ADD ./sshd_config /etc/ssh/sshd_config #配置文件见下段代码 RUN chown root:sftp /data/sftp/mysftp
RUN chmod 755 /data/sftp/mysftp RUN mkdir /data/sftp/mysftp/upload
RUN chown mysftp:sftp /data/sftp/mysftp/upload
RUN chmod 755 /data/sftp/mysftp/upload EXPOSE 22 #这个CMD命令挺重要的,耗了点时间测试,没事再看看
CMD /usr/sbin/sshd -D

2. 生成镜像文件,镜像名设置为sftp_test1
docker build -t sftp_test1
3. 其中上面代码中sshd_config配置文件如下

Port 22
Protocol 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
UsePrivilegeSeparation yes
KeyRegenerationInterval 3600
ServerKeyBits 1024
SyslogFacility AUTH
LogLevel INFO
LoginGraceTime 120
PermitRootLogin without-password
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication no
X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
AcceptEnv LANG LC_*
UsePAM yes
Subsystem sftp internal-sftp
Match Group sftp
ChrootDirectory /data/sftp/mysftp
ForceCommand internal-sftp
AllowTcpForwarding no

阿里云的ubuntu14的源文件如下

deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse

4. docker-compose 文件如下
sftp:
image: sftp_test1
volumes:
- /data/sftp/mysftp/upload/:/data/sftp/mysftp/upload/
ports:
- "4004:22"
这里需要把本机的/data/sftp/mysftp/upload的权限改为777,这样才能进行在sftp容器中进行文件上传
5. 在docker-compose文件夹中执行docker-compose up -d启动sftp容器,然后sftp -P 4004 mysftp@127.0.0.1 密码为123连上,进入upload文件夹中即可进行文件上传了
二. 网上有一个别人做的sftp镜像,但是按照他的方法上传有点问题
链接为http://www.mamicode.com/info-detail-2084477.html
写成自己的docker-compose文件为
sftp:
image: atmoz/sftp #冒号后面要后空格
volumes:
- /home/foo/test/:/home/foo/ #冒号前面不能有空格
# - /home/foo1/test1/:/home/foo1
ports:
- "2222:22"
command: foo:pass:1002 (foo1:pass:1003 #可以有多个用户)
解决方法如下
/home/foo/test文件夹授权755,在test目录下再新建一个文件夹,比如upload, 把需要上传的文件放置在upload中,并且修改upload权限为777
镜像作者的设定应该是把映射目录作为根目录(监狱),根目录是不能有写权限的,需要在下面再建一个子目录
docker部署sftp的更多相关文章
- docker 部署 flask(一)配置环境及测试
简介: flask也是要部署的.不能老在我们的pycharm里面跑测试服务器. 各种配置linux,我看就算了吧.我们用docker部署. 也就两三行命令. 一:选择基础镜像 GitHub repo: ...
- ASP.NET Core开发-Docker部署运行
ASP.NET Core开发Docker部署,.NET Core支持Docker 部署运行.我们将ASP.NET Core 部署在Docker 上运行. 大家可能都见识过Docker ,今天我们就详细 ...
- Docker部署Hadoop集群
Docker部署Hadoop集群 2016-09-27 杜亦舒 前几天写了文章"Hadoop 集群搭建"之后,一个朋友留言说希望介绍下如何使用Docker部署,这个建议很好,Doc ...
- 程序开发使用docker部署
我们公司自己研发了一套 grand-line 系统,使用 docker 来部署项目. 我是第一批小白鼠,一开始网络差,build 一次要半个小时,连接进入 web shell 也很慢,部署一个微信项目 ...
- 我使用celery以及docker部署遇到的问题
首先我本机测试时没有问题的,但是在线上docker中,任务一直显示 "Sending due task".超时的任务是 django orm update 操作,本地不会出现这样的 ...
- Docker部署SDN环境
2014-12-03 by muzi Docker image = Java class Docker container = Java object 前言 5月份的时候,当我还是一个大学生的时候,有 ...
- 在生产环境使用Docker部署应用
导读 Docker现在越来越流行,但是真正在生产环境部署Docker还是个比较新的概念,还没有一个标准的流程.作者是ROR的程序员,作者结合平时的部署经验,联系Docker的特点,向大家分享了其在生产 ...
- Docker 使用指南 (六)—— 使用 Docker 部署 Django 容器栈
版权声明:本文由田飞雨原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/98 来源:腾云阁 https://www.qclou ...
- NET Core Docker部署
NET Core Docker部署 前言 在前面文章中,介绍了 ASP.NET Core在 macOS,Linux 上基于Nginx和Jexus的发布和部署,本篇文章主要是如何在Docker容器中运行 ...
随机推荐
- SMTPSenderRefused: (530, ‘5.5.1 Authentication Required. Learn more at \n5.5.1
在跟着<Flask Web开发:基于Python的Web应用开发实战>一书学习时,出现了以上错误提示. 问题出于第11章--博客文章.当运行 python manage.py runser ...
- 开发 WebAPP 的几个前端框架(不断更新中)
http://mobileangularui.com/ http://ionicframework.com/ http://www.idangero.us/framework7/ (中文文档:http ...
- CSS块级元素、内联元素概念[转]
CSS文档流与块级元素(block).内联元素(inline),之前翻阅不少书籍,看过不少文章, 看到所多的是零碎的CSS布局基本知识,比较表面.看过O'Reilly的<CSS权威指南>, ...
- 手工创建Oracle数据库
数据库版本: SQL> select * from v$version; BANNER ----------------------------------------------------- ...
- 常用工具类——StringUtils
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreem ...
- [GO]errorr接口的使用
package main import ( "fmt" "errors" ) func main() { erro1 := fmt.Errorf("% ...
- css3之transform-origin
transform-origin属性平时似乎用得很少,它决定了变换时依赖的原点.基本的属性特性可以参考CSS手册. 如果在H5动画项目中,用到旋转的话,它还是不能小觑的. 假如我们做一个秋千效果 其实 ...
- 用word发CSDN blog
目前大部分的博客作者在用Word写博客这件事情上都会遇到以下3个痛点: 1.所有博客平台关闭了文档发布接口,用户无法使用Word,Windows Live Writer等工具来发布博客.使用Word写 ...
- Tango Java API常数
Tango Java API Constants常数 Constant Field Values常数字段值 Contents com.google.* com.google.* com.google. ...
- 使用Amazon Simple Queue Service(SQS) 实现简单的消息服务
一 引言 亚马逊Amazon作为云计算的领跑者推出了很多云服务,最近因为项目的原因,需要用到SQS服务,因此简要地写下这篇随笔,一来方便以后查阅,二来方便共享一些简单的操作. SQS即可以理解为一个 ...