I am running a service in a Docker container that needs to connect to a remote FTP server. While I can successfully connect to the FTP server from my host machine (using FTP clients like FileZilla or the command-line FTP client), the service in the Docker container fails to establish a connection.
Here's the setup:
- The service inside the Docker container needs to connect to the FTP server either at localhost or some test one as /
- The FTP server works fine when I connect from my host machine.
- I am using the following Docker setup:
version: '3.8'
services:
ftp-file-service:
build:
context: .
dockerfile: ftp-file-service/Dockerfile
container_name: ftp-file-service
ports:
- '8081:8081'
networks:
- common-network
extra_hosts:
- "host.docker.internal:host-gateway"
depends_on:
- redis
...
networks:
common-network:
driver: bridge
Problem: The FTP client inside the container is unable to connect to the remote FTP server.
What I have tried so far:
- I checked that the FTP server is accessible from the host machine (FileZilla connects without issues).
- I added the extra_hosts configuration to route the container's localhost to the host machine.
- I tried using the bridge network mode and confirmed that the container has Internet access, but still cannot connect to the FTP server.
Question: What is the correct configuration to enable the container to connect to an external FTP server from inside the container?