Docker Community Forums

Share and learn in the Docker community.

How to run vsftpd service when a container starts

Dear All,

I am facing a problem while setting up a docker container for FTP server. Any help will be appreciated.

My requirement is to run a docker container with ftp service with out any intervention. ie, vsftp service should run when docker starts and I tried to create a container with below steps but service is not starting automatically.

Things I have done.

  1. Docker rhel image imported and installed vsftpd service and configured ftp service.
  2. Added entry in /etc/rc.local " /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf " to run the service at startup
  3. commit the image to new name
  4. Created a container using new image and I could see all the configuration but ftp service is failed to start.
  5. Tried execute the sh /etc/rc.local and service is started ( Note : execute permission were given to /etc/rc.local )

Please share the exact command you used to start your container. I can only assume that you did not specify a restart policy in your command.

Also a ftp server might not the best kind of service to containerize, see https://stackoverflow.com/a/60692544/3460948. You would need to publish a huge range of passv ports for the container, which is possible, but will add a huge delay while starting the container.

Install vsftpd
Before installing new software, it’s always best practice to run updates:
yum -y update

Then install vsftpd and any required packages:
yum -y install vsftpd

Configure vsftpd
For a refresher on editing files with vim see: New User Tutorial: Overview of the Vim Text Editor
Edit vsftp Configurations
Now let’s edit the configuration file for vsftpd. Open the file with the following command:
vim /etc/vsftpd/vsftpd.conf

Now that the file is opened up you’ll want to make the following changes. Either find the option line and edit it, or simply delete it and replace with the lines noted here.
Disallow anonymous logins; this allows unidentified users to access files via FTP. Ensure that the anonymous_enable setting to NO:
anonymous_enable=NO

Enable local users to login, this will allow your regular user accounts to function as FTP accounts. Change the local_enable setting to YES:
local_enable=YES

If you want local user to be able to write to a directory, then change the write_enable setting to YES:
write_enable=YES

Local users will be ‘chroot jailed’ and they will be denied access to any other part of the server. Set the chroot_local_user setting to YES:
chroot_local_user=YES

Exit and save the file with the command :wq, or with :x.
Restart and Enable the vsftpd service:
First restart the service:
systemctl restart vsftpd

Then set the vsftpd service to start at boot:
systemctl enable vsftpd

Allow vsftpd Through the Firewall
Allow the default FTP port, port 21, through firewalld:
firewall-cmd --permanent --add-port=21/tcp

And reload the firewall:
firewall-cmd --reload
And that is it! You should now have vsftpd installed, setup and configured on your server. If you followed these directions you should now be able to login to the server via FTP! If you have a hardware firewall in addition to the servers software firewall, you may need to adjust those setting too.

I still don’t undstand why the moderator of this forum allows this stupid bot account lewish9 to harass people with its responses…

Thanks @meyay for your update.

I have installed vsftpd package on docker and configured user then allowed firewall port.

Container started using the below command

" docker run -it rhe_image.tar"

If I run vsftp after the container starts, It is working as expected but I want to start the vsftpd automatically when container starts.

To achieve this I have added below entry in /etc/rc.local but not working

" /usr/bin/vsftpd /etc/vsftpd/vsftpd.conf"

I am new to docker and not aware about restart policy.

Thanks for your time to review this question

Thanks @lewish95 for your reply.

I am able to start the vsftpd service manually on the docker. But I wanted it to start it automatically

For that an entry put on /etc/rc.local but it is not working

How is:

the response to this:

?

I specificly asked for the exact(!) command and not for a similar or redacted command.

@meyay Sorry for the confusion.

Recreated the issue and these are the steps I followed.

We already saved a rhel image from our internet machine with name rhel.tar and moved to docker host which is not having internet connectivity.

“docker image load -i rhel.tar”

“docker run -it --name rhel_base_os -v /sonas/sdclib/rhelyumrepo/rhel7.9:/mnt -v /docker_storage:/docker_storage registry.redhat.io/rhel

executed below commands inside docker

created yum repo on docker

“yum install net-tools iproute vsftpd”

“groupadd -g 207 opr”

“useradd -u 207 -g 207 -d /docker_storage/opr -m -s /bin/bash opr”

“passwd opr”

“chmod +x /etc/rc.d/rc.local”

added below line in /etc/rc.local

“/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf” -------> Got this from “/usr/lib/systemd/system/vsftpd.service”

Executed the following commands from docker host

“docker commit rhel_base_os rhel_ftp_server”

“docker run -it --name ftp_server1 rhel_ftp_server”

checked “ps -ef | grep vsftpd” but vsftpd service is not running.

You might want to search the forum for differences between (docker) containers and vms. You approach looks like you try to force vm patterns to the container world.

May I suggest to start of with a pre-existing image from Docker Hub, like fauria/vsftpd ? You can take a peek into its Dockerfile (in its github repo) and build up understanding on how to properly build an image…

Also, I’d like to suggest this fabulous free self-paced docker training: https://container.training/intro-selfpaced.yml.html. It helps a lot if you know at least the basics… knowledge beyond the basics doesn’t hurt either.

@meyay Sorry. I am new to docker and don’t have complete knowledge about docker.
Thanks for the link. I will go through this

Don’t be afraid of the number of slides, you can rush thru most of them within seconds. Perform all excercices to get a better understanding. Those are realy good training slides. Its definitly worth the time you spend to work them true!

Once you get a better understanding, things will get more clear :slight_smile:

Yeah no of pages are more it seems but contents are less in each slide and it can read fast.

Thanks for your guidance