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.

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

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

@meyay
I have gone through the document. It was very helpful for me.

And I created a new container for ftp by using the rhel base image.

Now I am able to start a container which start ftp service automatically.

Thank you @dewggg1150