微信扫一扫 分享朋友圈

已有 793 人浏览分享

开启左侧

docker搭建ftp服务器教程

[复制链接]
793 0
1)docker拉取ftp镜像
  1. docker pull fauria/vsftpd
复制代码
2)启动ftp镜像
  1. docker run -d -p 2121:21 -p 2020:20 -p 21100-21110:21100-21110 \
  2. -v /home/dispatch/ftp/root:/home/vsftpd/ftp \
  3. -e FTP_USER=ftp \
  4. -e FTP_PASS=123456 \
  5. -e PASV_ADDRESS=***.**.**.** \
  6. -e PASV_MIN_PORT=21100 \
  7. -e PASV_MAX_PORT=21110 \
  8. --name vsftpd \
  9. --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原因了。关于这个配置,等下看下配置文件就知道。

image.png
而 /home/dispatch/ftp/root 这个路径是应道宿主机的文件路径。这个可以随便写。
-e FTP_USER=ftp -e FTP_PASS=123456  分别为账号密码。
PASV_ADDRESS 为宿主机的IP

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

image.png
image.png
出现下面提示信息,即显示连接成功
image.png
我们在此新建一个文件夹
image.png
找到上面我们挂载的文件路径/home/dispatch/ftp/root ,打开就可以看到刚才新建的文件。同样在ftp服务器上文件的新增、删除、变更。使用ftp客户端都可以看到。至此docker版的ftp服务器就搭建完成。可以再去测试一下文件的上传下载。
image.png
4)关于上面作者所提到的坑
关于挂载路径设置的问题,其实在配置文件中的都有配置。
    1、进入ftp的docker容器
    docker exec -it vsftpd /bin/bash

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

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

  1. # Run in the foreground to keep the container running:
  2. background=NO

  3. # Allow anonymous FTP? (Beware - allowed by default if you comment this out).
  4. anonymous_enable=NO

  5. # Uncomment this to allow local users to log in.
  6. local_enable=YES

  7. ## Enable virtual users
  8. guest_enable=YES

  9. ## Virtual users will use the same permissions as anonymous
  10. virtual_use_local_privs=YES

  11. # Uncomment this to enable any form of FTP write command.
  12. # Run in the foreground to keep the container running:
  13. background=NO

  14. # Allow anonymous FTP? (Beware - allowed by default if you comment this out).
  15. anonymous_enable=NO

  16. # Uncomment this to allow local users to log in.
  17. local_enable=YES

  18. ## Enable virtual users
  19. guest_enable=YES

  20. ## Virtual users will use the same permissions as anonymous
  21. virtual_use_local_privs=YES

  22. # Uncomment this to enable any form of FTP write command.
  23. write_enable=YES

  24. ## PAM file name
  25. pam_service_name=vsftpd_virtual

  26. ## Home Directory for virtual users
  27. user_sub_token=$USER
  28. local_root=/home/vsftpd/$USER

  29. # You may specify an explicit list of local users to chroot() to their home
  30. # directory. If chroot_local_user is YES, then this list becomes a list of
  31. # users to NOT chroot().
  32. chroot_local_user=YES

  33. # Workaround chroot check.
  34. # See https://www.benscobie.com/fixing-500-oops-vsftpd-refusing-to-run-with-writable-root-inside-chroot/
  35. # and http://serverfault.com/questions/362619/why-is-the-chroot-local-user-of-vsftpd-insecure
  36. allow_writeable_chroot=YES
  37. # Run in the foreground to keep the container running:
  38. background=NO

  39. # Allow anonymous FTP? (Beware - allowed by default if you comment this out).
  40. anonymous_enable=NO

  41. # Uncomment this to allow local users to log in.
  42. local_enable=YES

  43. ## Enable virtual users
  44. guest_enable=YES

  45. ## Virtual users will use the same permissions as anonymous
  46. virtual_use_local_privs=YES

  47. # Uncomment this to enable any form of FTP write command.
  48. write_enable=YES

  49. ## PAM file name
  50. pam_service_name=vsftpd_virtual

  51. ## Home Directory for virtual users
  52. user_sub_token=$USER
  53. local_root=/home/vsftpd/$USER

  54. # You may specify an explicit list of local users to chroot() to their home
  55. # directory. If chroot_local_user is YES, then this list becomes a list of
  56. # users to NOT chroot().
  57. chroot_local_user=YES

  58. # Workaround chroot check.
  59. # See https://www.benscobie.com/fixing-500-oops-vsftpd-refusing-to-run-with-writable-root-inside-chroot/
  60. # and http://serverfault.com/questions/362619/why-is-the-chroot-local-user-of-vsftpd-insecure
  61. allow_writeable_chroot=YES

  62. ## Hide ids from user
  63. hide_ids=YES

  64. ## Enable logging
  65. xferlog_enable=YES
  66. xferlog_file=/var/log/vsftpd/vsftpd.log

  67. ## Enable active mode
  68. port_enable=YES
  69. connect_from_port_20=YES
  70. ftp_data_port=20

  71. ##| Disable seccomp filter sanboxing
  72. seccomp_sandbox=NO

  73. ### Variables set at container runtime
  74. pasv_address=192.168.0.16
  75. pasv_max_port=21110
  76. pasv_min_port=21100
  77. pasv_addr_resolve=NO
  78. pasv_enable=YES
  79. file_open_mode=0666
  80. local_umask=077
  81. xferlog_std_format=NO
  82. reverse_lookup_enable=YES
  83. pasv_promiscuous=NO
  84. port_promiscuous=NO
复制代码

免责声明:
1,海欣资源网所发布的资源由网友上传和分享,不保证信息的正确性和完整性,且不对因信息的不正确或遗漏导致的任何损失或损害承担责任。
2,海欣资源网的资源来源于网友分享,仅限用于学习交流和测试研究目的,不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。
3,海欣资源网所发布的资源由网友上传和分享,版权争议与本站无关,您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。
4,如果您喜欢,请支持正版,购买正版,得到更好的正版服务,如有侵权,请联系我们删除并予以真诚的道歉,联系方式邮箱 haixinst@qq.com
海欣资源-企业信息化分享平台。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

0

关注

0

粉丝

28

主题
热度排行
回复排行
最新贴子

Archiver|手机版|海欣资源 ( 湘ICP备2021008090号-1 )|网站地图

GMT+8, 2024-3-29 08:05 , Gzip On, MemCached On.

免责声明:本站所发布的资源和文章均来自网络,仅限用于学习交流和测试研究目的,不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。 本站信息来自网络,版权争议与本站无关,您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。 如果您喜欢,请支持正版,购买正版,得到更好的正版服务,如有侵权,请联系我们删除并予以真诚的道歉。