How to run rc.local in container

New to docker, long time user of LXC.

I’m running Rancher v2.0 and doing everything through its UI. Using ubuntu:latest docker image.

I’m trying to get a container to run a script at start, ideally rc.local, because I plan on bind mounting rc.local from the host to the container.

Editing rc.local in the container and stopping/starting doesn’t run rc.local

I’m out of ideas at the moment

I don’t think that the default ubuntu image tries to run rc.local. You would have to either set it as the command or entrypoint for the container.

What does a command or entry point look like? I’ve tried using a shell
command with full paths, but it didn’t work.

How does an entry point work, would you need to have the script mounted,
then configi the entry point to be the mounted script?

If you are using the UI to create a container, then in the Command tab, there is an option for Command and Entry point. You can try putting it in there. You would also need to put your custom rc.local file in the container, either by building your own custom container, or mounting it in as a volume.

Keep in mind, that the entrypoint/cmd needs to be program or script that runs in the foreground. If your rc.local script starts other programs in the background and then exits, you will not get the desired behavior because once the rc.local script completes, the container will end. This will cause Rancher to restart it, and it will loop.

If your goal is to run several other programs in your container, then you would be better off installing Supervisord (or a similar process manager) and having it manage your other programs. That way, Supervisord runs in the foreground of the container, and your other programs run in the background.

1 Like

Ohhhhh that makes a lot of sense now. So as long as either entrypoint or command continues running in the foreground, the container remains running.

I was wondering why the container stops after running a script.

This makes a lot more sense now. Thanks!

This should be the documentation for it.

This is a behavior of Docker, not Rancher. All Docker containers behave this way, regardless of orchestration, or whether you manually start a container.

Here’s some info from Docker.

Gotcha. Granted I just started using rancher/docker a couple days ago.