Docker File to support FTP and SFTP

Currently we are using SFTP server,it is built from below Docker file and it is working fine. Our requirement is to support both FTP and SFTP Protocol in the same container.
Below is the Dockerfile. Any help will be appreciated

FROM centos

ARG USER_ID=14
ARG GROUP_ID=50


LABEL Description="vsftpd Docker image based on Centos 7. Supports passive mode and virtual users." \
    License="Apache License 2.0" \
    Usage="docker run -d -p [HOST PORT NUMBER]:21 -v [HOST FTP HOME]:/home/vsftpd fauria/vsftpd" \
    Version="1.0"

RUN yum -y update && yum clean all
RUN yum install -y \ 
vsftpd \ 
db4-utils \ \n
db4 \ \n
iproute && yum clean all \n

RUN usermod -u ${USER_ID} ftp \n
RUN groupmod -g ${GROUP_ID} ftp \n

ENV FTP_USER **String** \n
ENV FTP_PASS **Random** \n
ENV PASV_ADDRESS **IPv4**\n
ENV PASV_ADDR_RESOLVE NO
ENV PASV_ENABLE YES
ENV PASV_MIN_PORT 21100
ENV PASV_MAX_PORT 21110
ENV XFERLOG_STD_FORMAT NO
ENV LOG_STDOUT **Boolean**
ENV FILE_OPEN_MODE 0666
ENV LOCAL_UMASK 077
ENV REVERSE_LOOKUP_ENABLE YES
COPY vsftpd.conf /etc/vsftpd/
COPY vsftpd_virtual /etc/pam.d/
COPY run-vsftpd.sh /usr/sbin/
RUN chmod +x /usr/sbin/run-vsftpd.sh
RUN mkdir -p /home/vsftpd/
RUN chown -R ftp:ftp /home/vsftpd/
VOLUME /home/vsftpd
VOLUME /var/log/vsftpd
EXPOSE 20 21 22
CMD ["/usr/sbin/run-vsftpd.sh"]

SFTP relies on ssh. It seems like vsftpd delegates the work to the os ssh package, instead of providing its own implementation.

You might want to search the forum on how to make ssh work inside a centos container. The problem is not the installation, the problem is to start the ssh daemon during container start as no systemd or init.d are available in the container.

Hi @meyay,

Thanks for your reply, can we use separate containers for FTP and SFTP with same persistent disk and same file to add users where FTP and sftp server uses the same file in text format. please suggest.

sorry, but i don’t know vsftp handles its users. Usualy sftp relies on linux users.

You can share a volume amaongst containers, if you use a bind-mount (-v /path/on/host:/path/in/container/ or a remote share as volume.