Docker从主机组成ftpd服务器访问

时间:2019-05-20 14:11:16

标签: docker docker-compose ftp-client

我正在尝试从主机访问ftpd服务器

使用ftp localhostftp <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服务器?

1 个答案:

答案 0 :(得分:1)

您可以将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.