Running vsftpd on Docker

Happy 2019!!

Lately I’ve been playing around with docker and decided to create a dockerfile to have vsftpd running on CentOS. Below is my dockerfile:

# Dockerfile for vsftpd on CentOS
FROM centos:7


RUN yum -y update; yum -y install which vsftpd net-tools vsftpd-sysvinit; yum clean all

COPY vusers.txt /etc/vsftpd/
RUN db_load -T -t hash -f /etc/vsftpd/vusers.txt /etc/vsftpd/vsftpd-virtual-user.db; rm -v /etc/vsftpd/vusers.txt; \ 
	chmod 600 /etc/vsftpd/vsftpd-virtual-user.db
COPY vsftpd.conf /etc/vsftpd/
COPY vsftpd.virtual /etc/pam.d/
RUN mkdir -p /home/vftp/ftpuser; chown -R ftp:ftp /home/vftp

EXPOSE 20 21

CMD ["/usr/sbin/vsftpd","-obackground=NO"]

We need to create three files before building the image, one for vsftpd virtual users PAM, another vsftpd.conf file and another with the virtual users. vsftpd.conf below:


Pam file, store as vsftpd.virtual

auth       required db=/etc/vsftpd/vsftpd-virtual-user
account    required db=/etc/vsftpd/vsftpd-virtual-user
session    required

And at last a file with user and password, which we will store as vusers.txt


All these files shall be stored into the same directory in order for build to be successful. We proceed building.

docker build -t centos-vsftpd -f  centos-vsftpd . 
Sending build context to Docker daemon  10.24kB
Step 1/10 : FROM centos:7
 ---> 1e1148e4cc2c
Step 2/10 : MAINTAINER
 ---> Using cache
 ---> cb00764989e4
Step 3/10 : RUN yum -y update; yum -y install which vsftpd net-tools vsftpd-sysvinit; yum clean all
 ---> Using cache
 ---> 84bc55dc256f
Step 4/10 : COPY vusers.txt /etc/vsftpd/
 ---> Using cache
 ---> 922453bc2ba3
Step 5/10 : RUN db_load -T -t hash -f /etc/vsftpd/vusers.txt /etc/vsftpd/vsftpd-virtual-user.db; rm -v /etc/vsftpd/vusers.txt; 	chmod 600 /etc/vsftpd/vsftpd-virtual-user.db
 ---> Using cache
 ---> 3f0f5a3743af
Step 6/10 : COPY vsftpd.conf /etc/vsftpd/
 ---> Using cache
 ---> f6241c5dc497
Step 7/10 : COPY vsftpd.virtual /etc/pam.d/
 ---> b768b27a3496
Removing intermediate container 45326ecc02a0
Step 8/10 : RUN mkdir -p /home/vftp/ftpuser; chown -R ftp:ftp /home/vftp
 ---> Running in fb940a0b999f
 ---> 8afff06f270a
Removing intermediate container fb940a0b999f
Step 9/10 : EXPOSE 20 21
 ---> Running in 0a9bd172c74e
 ---> d07e65112275
Removing intermediate container 0a9bd172c74e
Step 10/10 : CMD /usr/sbin/vsftpd -obackground=NO
 ---> Running in 50f124e366ee
 ---> 0a571ecf1fed
Removing intermediate container 50f124e366ee
Successfully built 0a571ecf1fed
Successfully tagged centos-vsftpd:latest

We now start the vsftpd container and check its running.

docker run -d --name myftp centos-vsftpd:latest; docker ps 
CONTAINER ID        IMAGE                  COMMAND                  CREATED                  STATUS                  PORTS               NAMES
1034cc745e43        centos-vsftpd:latest   "/usr/sbin/vsftpd ..."   Less than a second ago   Up Less than a second   20-21/tcp           myftp

We connect to newly created ftp server and upload a test file.

Connected to
220 (vsFTPd 3.0.2)
Name ( ftpuser
331 Please specify the password.
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> mput test.txt
mput test.txt? y
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 Transfer complete.
10 bytes sent in 0.00 secs (187.8005 kB/s)

And we check the creation and content of the uploaded file.

docker exec myftp cat  /home/vftp/ftpuser/test.txt
Test File


2 thoughts on “Running vsftpd on Docker

  1. elwyn5150


    Thanks for writing this. I’ve been struggling for the past week to get vsftpd running. It’s helpful to have someone share all their files to get things running.

    I do have a couple of questions. I had to save the Dockerfile contents as “centos-vsftpd” to get the build to run.

    Also, is the IP address of your computer? I’ve been able to install vsftpd using other Docker instructions but never connected to it because the connection would be refused. So I’m not sure what I should be entering for the vsftpd server’s host and port number.

  2. Xavi Post author


    Thanks for dropping by.

    Regarding the questions, doesn’t really matters how you call the file but I think it’s a good practice naming it so it can give you an idea what it is. Check out docker build help. In the article I’m tagging(-t) the build as centos-vsftpd and giving path to docker file (-f). Now when I search for docker image it won’t have some weird name.

    docker images | grep centos-vsftpd
    centos-vsftpd           latest              f43e1e778396        10 months ago       226MB

    As per the class B IP that comes with docker networking. Use docker network to check your docker network.

    user@computer: ~ $ /sbin/ifconfig docker0 | grep inet | grep -v inet6;  docker run -d --name myftp centos-vsftpd:latest
            inet  netmask  broadcast
    user@computer: ~ $ docker ps 
    CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS               NAMES
    0ec967b75281        centos-vsftpd:latest   "/usr/sbin/vsftpd ..."   51 seconds ago      Up 49 seconds       20-21/tcp           myftp
    user@computer: ~ $ 
    user@computer: ~ $  docker network inspect bridge | egrep "(Name|IPv4Add)"
            "Name": "bridge",
                    "Name": "myftp",
                    "IPv4Address": "",
    user@computer: ~ $ telnet 21
    Connected to
    Escape character is '^]'.
    220 (vsFTPd 3.0.2)

Leave a Reply