Контейнер для настройки Apache ftpserver

#java #apache #ftp-server

#java #apache #ftp-сервер

Вопрос:

Я пытаюсь запустить службу FTP, используя Apache ftpserver в контейнере docker. Контейнер запускается без проблем и может войти в систему. Однако ему не удается установить соединение для передачи данных с использованием пассивного режима. Пока что он запущен локально, а внешний ip не установлен, поэтому я бы предположил, что он использует внутренний локальный ip.

Я пытался с установкой внешнего IP-адреса или без него (setPassiveExternalAddress), но безуспешно.

Кто-нибудь успешно запускал Apache ftpserver с контейнером docker?

 java.net.BindException: Address in use (Bind failed)
    at java.net.PlainSocketImpl.socketBind(Native Method) ~[na:1.8.0_151]
    at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:387) ~[na:1.8.0_151]
    at java.net.Socket.bind(Socket.java:644) ~[na:1.8.0_151]
    at org.apache.ftpserver.impl.IODataConnectionFactory.createDataSocket(IODataConnectionFactory.java:309) [ftpserver-core-1.1.1.jar:1.1.1]
    at org.apache.ftpserver.impl.IODataConnectionFactory.openConnection(IODataConnectionFactory.java:257) [ftpserver-core-1.1.1.jar:1.1.1]
    at org.apache.ftpserver.command.impl.LIST.execute(LIST.java:115) [ftpserver-core-1.1.1.jar:1.1.1]
    at org.apache.ftpserver.impl.DefaultFtpHandler.messageReceived(DefaultFtpHandler.java:211) [ftpserver-core-1.1.1.jar:1.1.1]
    at org.apache.ftpserver.listener.nio.FtpHandlerAdapter.messageReceived(FtpHandlerAdapter.java:62) [ftpserver-core-1.1.1.jar:1.1.1]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.messageReceived(DefaultIoFilterChain.java:858) [mina-core-2.0.16.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:542) [mina-core-2.0.16.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1300(DefaultIoFilterChain.java:48) [mina-core-2.0.16.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:947) [mina-core-2.0.16.jar:na]
    at org.apache.ftpserver.listener.nio.FtpLoggingFilter.messageReceived(FtpLoggingFilter.java:85) [ftpserver-core-1.1.1.jar:1.1.1]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:542) [mina-core-2.0.16.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1300(DefaultIoFilterChain.java:48) [mina-core-2.0.16.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:947) [mina-core-2.0.16.jar:na]
    at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:74) [mina-core-2.0.16.jar:na]
    at org.apache.mina.filter.logging.MdcInjectionFilter.filter(MdcInjectionFilter.java:135) [mina-core-2.0.16.jar:na]
    at org.apache.mina.filter.util.CommonEventFilter.messageReceived(CommonEventFilter.java:70) [mina-core-2.0.16.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:542) [mina-core-2.0.16.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1300(DefaultIoFilterChain.java:48) [mina-core-2.0.16.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:947) [mina-core-2.0.16.jar:na]
    at org.apache.mina.filter.codec.ProtocolCodecFilter$ProtocolDecoderOutputImpl.flush(ProtocolCodecFilter.java:398) [mina-core-2.0.16.jar:na]
    at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:234) [mina-core-2.0.16.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:542) [mina-core-2.0.16.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1300(DefaultIoFilterChain.java:48) [mina-core-2.0.16.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:947) [mina-core-2.0.16.jar:na]
    at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:74) [mina-core-2.0.16.jar:na]
    at org.apache.mina.core.session.IoEvent.run(IoEvent.java:63) [mina-core-2.0.16.jar:na]
    at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:770) [mina-core-2.0.16.jar:na]
    at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:762) [mina-core-2.0.16.jar:na]
    at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:704) [mina-core-2.0.16.jar:na]
    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151]
  

Ответ №1:

Этот файл Dockerfile работает для меня (смотрите Комментарии внутри о том, как его использовать)

 FROM openjdk:13-jdk-alpine

# Build this with:
# docker build -t "apache_mina_ftpserver:1.1.1" .

# Run this with:
# docker run -v /tmp:apache-ftpserver-1.1.1/res/home/ -p 2121-2199:2121-2199 -d apache_mina_ftpserver:1.1.1

# Then connect with
# ftp -p localhost 2121
# and log in with admin:admin

RUN wget https://archive.apache.org/dist/mina/ftpserver/1.1.1/dist/apache-ftpserver-1.1.1.zip
RUN unzip -q apache-ftpserver-1.1.1.zip

# configure additional passive ports
RUN sed -i 's#</ssl>#</ssl><data-connection><passive ports="2122-2199"/></data-connection>#g' apache-ftpserver-1.1.1/res/conf/ftpd-typical.xml

EXPOSE 2121-2199
CMD ["sh", "-c", "apache-ftpserver-1.1.1/bin/ftpd.sh res/conf/ftpd-typical.xml"]
  

Ответ №2:

Основываясь на конфигурации Orbiter, я изменил ее на порт 21. А также исправлена опечатка в его файле docker.

 FROM openjdk:13-jdk-alpine

# Build this with:
# docker build -t "apache_mina_ftpserver:1.1.1" .

# Run this with:
# docker run --name ftpd -v /tmp:/apache-ftpserver-1.1.1/res/home/:z -p 2122-2199:2122-2199 -p 21:21 -d apache_mina_ftpserver:1.1.1

# Then connect with
# ftp -p localhost 21
# and log in with admin:admin

RUN wget https://archive.apache.org/dist/mina/ftpserver/1.1.1/dist/apache-ftpserver-1.1.1.zip
RUN unzip -q apache-ftpserver-1.1.1.zip

# configure additional passive ports
RUN sed -i 's#</ssl>#</ssl><data-connection><passive ports="2122-2199"/></data-connection>#g' apache-ftpserver-1.1.1/res/conf/ftpd-typical.xml
RUN sed -i 's/2121/21/g' apache-ftpserver-1.1.1/res/conf/ftpd-typical.xml

# If you'd like to configure the admin password, remove the comment of below line and change <yourpassword> to your own password. Get your password by using echo -n 'yourpassword' | md5sum
# RUN sed -i 's/21232F297A57A5A743894A0E4A801FC3/<yourpassword>/g' apache-ftpserver-1.1.1/res/conf/users.properties

EXPOSE 21
EXPOSE 2122-2199
CMD ["sh", "-c", "apache-ftpserver-1.1.1/bin/ftpd.sh res/conf/ftpd-typical.xml"]