dockerdocker-composeftp-client

Docker compose ftpd-server access from host


I'm using trying to access a ftpd-server from the host

Using ftp localhost or ftp <my_ip>

But I'm getting 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

Since I'm using PUBLICHOST: "0.0.0.0" and port forward 21:21 I was expecting to be able to connect.

Docker Log

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

How can I achieve to connect from host machine to my ftp server on the container?


Solution

  • You can add network_mode: host to your service definition to make it work.

    services:
      ftpd-server:
        # ...
        network_mode: host
        # ...
    

    Then test with:

    $ 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.