欢迎光临
我们一直在努力

使用docker搭建ftp服务器

最近在做的一个调度系统的需求里,有一个需求,需要用到ftp服务器进行文件的下载和上传。刚好新分配的两个linux服务器上没有搭建ftp,想着就用docker安装一下。

安装的方式,参照:Linux下使用docker搭建ftp服务器 - william_zhao - 博客园

顺序无非,拉取镜像,启动镜像,访问服务器。

1)docker拉取ftp镜像

docker pull fauria/vsftpd

2)启动ftp镜像

docker run -d -p 2121:21 -p 2020:20 -p 21100-21110:21100-21110 \ -v /home/dispatch/ftp/root:/home/vsftpd/ftp \ -e FTP_USER=ftp \ -e FTP_PASS=123456 \ -e PASV_ADDRESS=***.**.**.** \ -e PASV_MIN_PORT=21100 \ -e PASV_MAX_PORT=21110 \ --name vsftpd \ --restart=always fauria/vsftpd

参数解释:

-p 2121:21 -p 2020:20 映射daocker和宿主机的端口号,通过ftp客户端,连接宿主机的2121端口,可以连接ftp服务器。2020端口,为docker映射到宿主机的数据传输端口。

-v /home/dispatch/ftp/root:/home/vsftpd/ftp 挂载的本机文件路径。注意:这个地方是有一个坑。/home/vsftpd/ftp 为docker-ftp的文件存放路径。这个不可以随便写,并且,每个人的也都不一样。路径格式为/home/vsftpd/${user} ${user} 为我后面设置的用户名。也就是FTP_USER=ftp。所以上面那个作者,设置了自己账户名为root之后,他的挂载源路径就为什么必须是root原因了。关于这个配置,等下看下配置文件就知道。

使用docker搭建ftp服务器

/home/dispatch/ftp/root 这个路径是应道宿主机的文件路径。这个可以随便写。

-e FTP_USER=ftp -e FTP_PASS=123456 分别为账号密码。

PASV_ADDRESS 为宿主机的IP

3)启动成功之后,使用ftp客户端连接上我们的ftp服务器。 我用的是CuteFtp 9.0

使用docker搭建ftp服务器

使用docker搭建ftp服务器

出现下面提示信息,即显示连接成功

使用docker搭建ftp服务器

我们在此新建一个文件夹

使用docker搭建ftp服务器

找到上面我们挂载的文件路径/home/dispatch/ftp/root ,打开就可以看到刚才新建的文件。同样在ftp服务器上文件的新增、删除、变更。使用ftp客户端都可以看到。至此docker版的ftp服务器就搭建完成。可以再去测试一下文件的上传下载。

使用docker搭建ftp服务器

4)关于上面作者所提到的坑

关于挂载路径设置的问题,其实在配置文件中的都有配置。

1、进入ftp的docker容器

docker exec -it vsftpd /bin/bash

2、打开/etc/vsftpd/vsftpd.conf

vi /etc/vsftpd/vsftpd.conf

使用docker搭建ftp服务器

这个也就是挂载到宿主机的ftp文件路径。也就是跟每个用户名是相关的。不同的用户名,对应不同的文件路径。当然也可以自行修改配置。建议把配置文件和log日志也挂在本地

贴出整个配置文件。如下:

# Run in the foreground to keep the container running: background=NO # Allow anonymous FTP? (Beware - allowed by default if you comment this out). anonymous_enable=NO # Uncomment this to allow local users to log in. local_enable=YES ## Enable virtual users guest_enable=YES ## Virtual users will use the same permissions as anonymous virtual_use_local_privs=YES # Uncomment this to enable any form of FTP write command. # Run in the foreground to keep the container running: background=NO # Allow anonymous FTP? (Beware - allowed by default if you comment this out). anonymous_enable=NO # Uncomment this to allow local users to log in. local_enable=YES ## Enable virtual users guest_enable=YES ## Virtual users will use the same permissions as anonymous virtual_use_local_privs=YES # Uncomment this to enable any form of FTP write command. write_enable=YES ## PAM file name pam_service_name=vsftpd_virtual ## Home Directory for virtual users user_sub_token=$USER local_root=/home/vsftpd/$USER # You may specify an explicit list of local users to chroot() to their home # directory. If chroot_local_user is YES, then this list becomes a list of # users to NOT chroot(). chroot_local_user=YES # Workaround chroot check. # See https://www.benscobie.com/fixing-500-oops-vsftpd-refusing-to-run-with-writable-root-inside-chroot/ # and http://serverfault.com/questions/362619/why-is-the-chroot-local-user-of-vsftpd-insecure allow_writeable_chroot=YES # Run in the foreground to keep the container running: background=NO # Allow anonymous FTP? (Beware - allowed by default if you comment this out). anonymous_enable=NO # Uncomment this to allow local users to log in. local_enable=YES ## Enable virtual users guest_enable=YES ## Virtual users will use the same permissions as anonymous virtual_use_local_privs=YES # Uncomment this to enable any form of FTP write command. write_enable=YES ## PAM file name pam_service_name=vsftpd_virtual ## Home Directory for virtual users user_sub_token=$USER local_root=/home/vsftpd/$USER # You may specify an explicit list of local users to chroot() to their home # directory. If chroot_local_user is YES, then this list becomes a list of # users to NOT chroot(). chroot_local_user=YES # Workaround chroot check. # See https://www.benscobie.com/fixing-500-oops-vsftpd-refusing-to-run-with-writable-root-inside-chroot/ # and http://serverfault.com/questions/362619/why-is-the-chroot-local-user-of-vsftpd-insecure allow_writeable_chroot=YES ## Hide ids from user hide_ids=YES ## Enable logging xferlog_enable=YES xferlog_file=/var/log/vsftpd/vsftpd.log ## Enable active mode port_enable=YES connect_from_port_20=YES ftp_data_port=20 ##| Disable seccomp filter sanboxing seccomp_sandbox=NO ### Variables set at container runtime pasv_address=192.168.0.16 pasv_max_port=21110 pasv_min_port=21100 pasv_addr_resolve=NO pasv_enable=YES file_open_mode=0666 local_umask=077 xferlog_std_format=NO reverse_lookup_enable=YES pasv_promiscuous=NO port_promiscuous=NO 

参数的解释可以另行搜索

原文链接:https://blog.csdn.net/weixin_41753664/article/details/123374929?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522166937964916782412544754%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=166937964916782412544754&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-18-123374929-null-null.nonecase&utm_term=%E6%9C%8D%E5%8A%A1%E5%99%A8

  • 海报
海报图正在生成中...
赞(0) 打赏
声明:
1、本博客不从事任何主机及服务器租赁业务,不参与任何交易,也绝非中介。博客内容仅记录博主个人感兴趣的服务器测评结果及一些服务器相关的优惠活动,信息均摘自网络或来自服务商主动提供;所以对本博客提及的内容不作直接、间接、法定、约定的保证,博客内容也不具备任何参考价值及引导作用,访问者需自行甄别。
2、访问本博客请务必遵守有关互联网的相关法律、规定与规则;不能利用本博客所提及的内容从事任何违法、违规操作;否则造成的一切后果由访问者自行承担。
3、未成年人及不能独立承担法律责任的个人及群体请勿访问本博客。
4、一旦您访问本博客,即表示您已经知晓并接受了以上声明通告。
文章名称:《使用docker搭建ftp服务器》
文章链接:https://www.456zj.com/33659.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址