NodeJS application stops working when containerised [FTP server in a container]

后端 未结 2 1095
野性不改
野性不改 2021-01-22 00:11

I am trying to containerise an ftp server NodeJS application. It works fine when I run it with npm but it does not respond when I run it inside of a container.

This is th

相关标签:
2条回答
  • 2021-01-22 00:49

    Listen on 0.0.0.0:5000 in the container, with passive ports defined

    const FtpSvr = require ( 'ftp-srv' );
      
    const hostname = '0.0.0.0';
    const port = 5000;
    
    const ftpServer = new FtpSvr ({
      url: `ftp://${hostname}:${port}`,
      anonymous: true,
      pasv_url: `ftp://${hostname}:${port}`,
      pasv_min: 65500,
      pasv_max: 65515,
    });
    

    Build the container as is and then run with the following ports mapped, which can all be used in an ftp connection:

    docker run -p 5000:5000 -p 65500-65515:65500-65515 --rm rrakshak/ftp-demo
    

    Gives the response:

    $ curl ftp://localhost:5000
    -rw-r--r-- 1 1 1          141 Oct 21 01:22 Dockerfile
    drwxr-xr-x 1 1 1         4096 Oct 21 01:21 node_modules
    -rw-r--r-- 1 1 1        21137 Oct 21 01:21 package-lock.json
    -rw-r--r-- 1 1 1           52 Oct 21 01:21 package.json
    -rw-r--r-- 1 1 1          660 Oct 21 01:23 server.js
    -rw-r--r-- 1 1 1        20287 Oct 21 01:21 yarn.lock
    

    The ftp client must be set to use passive mode.

    When an FTP client is in active mode, the FTP server receives a PORT command from the client and creates a new TCP connection from the container back out to the client for data on that PORT.

    Due to the Docker port mapping into the container, the source address of this data connection often won't match what the FTP client is using as the initial destination for the FTP server. Similar issues occur when setting up FTP servers behind NAT on classic servers.

    0 讨论(0)
  • 2021-01-22 00:54

    Try binding to 0.0.0.0. As you are running inside Docker, it will not work to bind against 127.0.0.1, as the request will come from outside (at least, from the perspective of the Docker container).

    For hints on troubleshooting these kind of network issues, you can find some ideas in the answer to this related question.

    0 讨论(0)
提交回复
热议问题