Docker 编写来自主机的 ftpd 服务器访问
Docker compose ftpd-server access from host
我正在尝试从主机
访问ftpd-server
使用 ftp localhost
或 ftp <my_ip>
但我得到 ftp: connect: Connection refused
version: '3'
services:
ftpd-server:
container_name: ftpd-server
image: stilliard/pure-ftpd:hardened
ports:
- 21:21
- 20:20
- 30000-30009:30000-30009
volumes:
- './ftp/data:/home/username/'
- './ftp/pass:/etc/pure-ftpd/passwd'
environment:
PUBLICHOST: "0.0.0.0"
FTP_USER_NAME: "user"
FTP_USER_PASS: "pass"
FTP_USER_HOME: "/home/username"
restart: always
因为我使用的是 PUBLICHOST: "0.0.0.0"
和端口转发 21:21
,所以我希望能够连接。
Docker日志
Removing ftpd-server ... done
Removing network mytest_default
No stopped containers
Creating network "mytest_default" with the default driver
Creating ftpd-server ...
Creating ftpd-server ... done
Attaching to ftpd-server
ftpd-server | Creating user...
ftpd-server | Password:
ftpd-server | Enter it again:
ftpd-server | Setting default port range to: 30000:30009
ftpd-server | Setting default max clients to: 5
ftpd-server | Setting default max connections per ip to: 5
ftpd-server | Starting Pure-FTPd:
ftpd-server | pure-ftpd -l puredb:/etc/pure-ftpd/pureftpd.pdb -E -j -R -P 0.0.0.0 -s -A -j -Z -H -4 -E -R -G -X -x -p 30000:30009 -c 5 -C 5
如何实现从主机连接到容器上的 ftp 服务器?
您可以将 network_mode: host
添加到您的服务定义中以使其工作。
services:
ftpd-server:
# ...
network_mode: host
# ...
然后测试:
$ ftp -p localhost 21
Connected to localhost.
220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
220-You are user number 1 of 5 allowed.
220-Local time is now 16:04. Server port: 21.
220-This is a private system - No anonymous login
220 You will be disconnected after 15 minutes of inactivity.
我正在尝试从主机
访问ftpd-server使用 ftp localhost
或 ftp <my_ip>
但我得到 ftp: connect: Connection refused
version: '3'
services:
ftpd-server:
container_name: ftpd-server
image: stilliard/pure-ftpd:hardened
ports:
- 21:21
- 20:20
- 30000-30009:30000-30009
volumes:
- './ftp/data:/home/username/'
- './ftp/pass:/etc/pure-ftpd/passwd'
environment:
PUBLICHOST: "0.0.0.0"
FTP_USER_NAME: "user"
FTP_USER_PASS: "pass"
FTP_USER_HOME: "/home/username"
restart: always
因为我使用的是 PUBLICHOST: "0.0.0.0"
和端口转发 21:21
,所以我希望能够连接。
Docker日志
Removing ftpd-server ... done
Removing network mytest_default
No stopped containers
Creating network "mytest_default" with the default driver
Creating ftpd-server ...
Creating ftpd-server ... done
Attaching to ftpd-server
ftpd-server | Creating user...
ftpd-server | Password:
ftpd-server | Enter it again:
ftpd-server | Setting default port range to: 30000:30009
ftpd-server | Setting default max clients to: 5
ftpd-server | Setting default max connections per ip to: 5
ftpd-server | Starting Pure-FTPd:
ftpd-server | pure-ftpd -l puredb:/etc/pure-ftpd/pureftpd.pdb -E -j -R -P 0.0.0.0 -s -A -j -Z -H -4 -E -R -G -X -x -p 30000:30009 -c 5 -C 5
如何实现从主机连接到容器上的 ftp 服务器?
您可以将 network_mode: host
添加到您的服务定义中以使其工作。
services:
ftpd-server:
# ...
network_mode: host
# ...
然后测试:
$ ftp -p localhost 21
Connected to localhost.
220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
220-You are user number 1 of 5 allowed.
220-Local time is now 16:04. Server port: 21.
220-This is a private system - No anonymous login
220 You will be disconnected after 15 minutes of inactivity.