2

我在 Windows 主机上的 Docker 容器中运行 ftp 服务器。我已经为 SSH 和 FTP 映射(-p)端口 22 和 21。我无法从主机成功 FTP 连接到 ftp 服务器。看起来 ftp 客户端(可爱的 FTP)使用随机端口来列出目录和文件,这就是连接断开的地方。使用凭据查看日志连接会成功,但后来到列出目录时它失败并断开连接。我试图弄清楚如何在 Docker 容器中设置 ftps 服务器,其中 ftp 客户端使用随机端口进行成功连接。仅供参考,我尝试了 PORT 和 PASIVE 连接类型,但都没有工作。这是我的 cutftp 连接日志:

*** CuteFTP 8.0 - build Aug 22 2006 ***

STATUS:>    [2/13/2019 11:22:56 AM] Getting listing ""...
STATUS:>    [2/13/2019 11:22:56 AM] Resolving host name localhost...
STATUS:>    [2/13/2019 11:22:56 AM] Host name localhost resolved: ip = 127.0.0.1.
STATUS:>    [2/13/2019 11:22:56 AM] Connecting to FTP server... localhost:2121 (ip = 127.0.0.1)...
STATUS:>    [2/13/2019 11:22:56 AM] Socket connected. Waiting for welcome message...
        [2/13/2019 11:22:56 AM] 220 (vsFTPd 3.0.3)
STATUS:>    [2/13/2019 11:22:56 AM] Connected. Authenticating...
COMMAND:>   [2/13/2019 11:22:56 AM] USER ftpuser
        [2/13/2019 11:22:56 AM] 331 Please specify the password.
COMMAND:>   [2/13/2019 11:22:56 AM] PASS *****
        [2/13/2019 11:22:56 AM] 230 Login successful.
STATUS:>    [2/13/2019 11:22:56 AM] Login successful.
COMMAND:>   [2/13/2019 11:22:56 AM] PWD
        [2/13/2019 11:22:56 AM] 257 "/" is the current directory
STATUS:>    [2/13/2019 11:22:56 AM] Home directory: /
COMMAND:>   [2/13/2019 11:22:56 AM] FEAT
        [2/13/2019 11:22:56 AM] Informational Message Only:
        211-Features:
         EPRT
         EPSV
         MDTM
         PASV
         REST STREAM
         SIZE
         TVFS
        211 End
STATUS:>    [2/13/2019 11:22:56 AM] This site supports features.
STATUS:>    [2/13/2019 11:22:56 AM] This site supports SIZE.
STATUS:>    [2/13/2019 11:22:56 AM] This site can resume broken downloads.
COMMAND:>   [2/13/2019 11:22:56 AM] REST 0
        [2/13/2019 11:22:56 AM] 350 Restart position accepted (0).
COMMAND:>   [2/13/2019 11:22:56 AM] PASV
        [2/13/2019 11:22:56 AM] 227 Entering Passive Mode (172,17,0,2,202,168).
STATUS:>    [2/13/2019 11:22:56 AM] Substituting received PASV address 172.17.0.2 to server address 127.0.0.1.
COMMAND:>   [2/13/2019 11:22:56 AM] LIST
STATUS:>    [2/13/2019 11:22:56 AM] Connecting FTP data socket... 127.0.0.1:51880...
ERROR:>     [2/13/2019 11:22:57 AM] The remote host actively refused the attempt to connect to it.
        1) Verify that the destination server name or IP address is correct
        2) Verify that the connection port number is correct (under Site Settings | Type tab).
        3) The remote server may be temporarily or permanently inaccessible (try again later).
        4) Verify that you have chosen the right protocol (SSH2, SSL, FTP, etc.) and have setup all required options for that protocol.
        5) Verify that the destination IP address and port numbers are correct.
        6) The remote server may be refusing multiple connections from the same client. Try using only one connection thread when connecting to this particular server (Site Settings | Options).
        7) Try pinging the address.
        8) If you are using a router, verify the router is up and running (check by pinging it and then ping an address outside of the router).
        9) Do a traceroute to the destination to verify all routers along the connection path are operational.
        10) Verify that your subnet mask is setup properly.
        11) Verify that your local software or hardware firewall is not blocking outbound connections originating from CuteFTP.
        12) Verify that your anti-virus software is not at fault (try disabling it).
ERROR:>     [2/13/2019 11:22:57 AM] PASV failed, trying PORT.
STATUS:>    [2/13/2019 11:22:57 AM] Waiting 0 seconds...
STATUS:>    [2/13/2019 11:22:57 AM] Getting listing "/"...
STATUS:>    [2/13/2019 11:22:57 AM] Resolving host name localhost...
STATUS:>    [2/13/2019 11:22:57 AM] Host name localhost resolved: ip = 127.0.0.1.
STATUS:>    [2/13/2019 11:22:57 AM] Connecting to FTP server... localhost:2121 (ip = 127.0.0.1)...
STATUS:>    [2/13/2019 11:22:57 AM] Socket connected. Waiting for welcome message...
        [2/13/2019 11:22:57 AM] 220 (vsFTPd 3.0.3)
STATUS:>    [2/13/2019 11:22:57 AM] Connected. Authenticating...
COMMAND:>   [2/13/2019 11:22:57 AM] USER ftpuser
        [2/13/2019 11:22:57 AM] 331 Please specify the password.
COMMAND:>   [2/13/2019 11:22:57 AM] PASS *****
        [2/13/2019 11:22:57 AM] 230 Login successful.
STATUS:>    [2/13/2019 11:22:57 AM] Login successful.
COMMAND:>   [2/13/2019 11:22:57 AM] PWD
        [2/13/2019 11:22:57 AM] 257 "/" is the current directory
STATUS:>    [2/13/2019 11:22:57 AM] Home directory: /
STATUS:>    [2/13/2019 11:22:57 AM] This site supports features.
STATUS:>    [2/13/2019 11:22:57 AM] This site supports SIZE.
STATUS:>    [2/13/2019 11:22:57 AM] This site can resume broken downloads.
COMMAND:>   [2/13/2019 11:22:57 AM] REST 0
        [2/13/2019 11:22:57 AM] 350 Restart position accepted (0).
COMMAND:>   [2/13/2019 11:22:57 AM] PORT 127,0,0,1,205,112
        [2/13/2019 11:22:57 AM] 500 Illegal PORT command.
ERROR:>     [2/13/2019 11:22:57 AM] Syntax error: command unrecognized.
ERROR:>     [2/13/2019 11:22:57 AM] Failed to establish data socket.

我运行以下命令来启动 ubuntu 容器

docker -dit --name ubuntu -p 80:80 -p 22:22 -p 21:21 ubuntu
docker exec -it ubuntu bash
apt update
apt install vfstpd

用所需的更改编辑了 vsftpd.conf。根据 cutftp 日志,我获得了成功的连接,但没有列出目录和文件,因为 cutftp 正在使用随机端口进行会话来显示文件和目录。我只有端口 80、22 和 21 映射到容器。

没有用例。我是码头工人的新手,到处玩耍和学习。我想运行 ubuntu 容器,然后在其上安装 LAMP。我成功安装了 LAMP,但随后需要 FTP 服务器将文件上传到 html 文件夹以测试站点。这只是学习。我知道我可以找到已经安装了 LAMP 的 docker 图像,但这不是学习。我确实对运行 ubuntu 容器有疑问,我相信我已经单独提出过(单独的问题)并等待有人回复。

根据你的建议,我已经尝试过

 docker run -dit --name ubuntu --network host ubuntu

这没有用。我什至无法对容器进行 SSH,所以看起来 --network host 不会将所有端口传递给容器。

4

0 回答 0