# How to run rc.local in container

**URL:** <https://forums.suse.com/t/how-to-run-rc-local-in-container/8043>\
**Category:** Rancher 1.x\
**Created:** [December 14, 2017, 7:26am UTC](https://forums.suse.com/t/how-to-run-rc-local-in-container/8043 "2017-12-14T07:26:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![naisanza](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/naisanza/32/3120_2.png) [@naisanza](https://forums.suse.com/u/naisanza)\
**Post date:** [December 14, 2017, 7:26am UTC](https://forums.suse.com/t/how-to-run-rc-local-in-container/8043/1 "2017-12-14T07:26:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![shubbard343](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@shubbard343](https://forums.suse.com/u/shubbard343)\
**Post date:** [December 19, 2017, 7:51pm UTC](https://forums.suse.com/t/how-to-run-rc-local-in-container/8043/2 "2017-12-19T19:51:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![naisanza](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/naisanza/32/3120_2.png) [@naisanza](https://forums.suse.com/u/naisanza)\
**Post date:** [December 20, 2017, 1:58am UTC](https://forums.suse.com/t/how-to-run-rc-local-in-container/8043/3 "2017-12-20T01:58:52Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![shubbard343](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@shubbard343](https://forums.suse.com/u/shubbard343)\
**Post date:** [December 20, 2017, 8:12pm UTC](https://forums.suse.com/t/how-to-run-rc-local-in-container/8043/4 "2017-12-20T20:12:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![naisanza](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/naisanza/32/3120_2.png) [@naisanza](https://forums.suse.com/u/naisanza)\
**Post date:** [December 21, 2017, 9:19am UTC](https://forums.suse.com/t/how-to-run-rc-local-in-container/8043/5 "2017-12-21T09:19:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![shubbard343](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@shubbard343](https://forums.suse.com/u/shubbard343)\
**Post date:** [December 21, 2017, 6:12pm UTC](https://forums.suse.com/t/how-to-run-rc-local-in-container/8043/6 "2017-12-21T18:12:47Z")

</div>

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.

> **[Run multiple services in a container](https://docs.docker.com/engine/admin/multi-service_container/)**
>
> A container’s main running process is the ENTRYPOINT and/or CMD at the end of the Dockerfile. It is generally recommended that you separate areas of concern by using one service...

---

<div class="post-metadata">

**Author:** ![naisanza](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/naisanza/32/3120_2.png) [@naisanza](https://forums.suse.com/u/naisanza)\
**Post date:** [December 21, 2017, 9:22pm UTC](https://forums.suse.com/t/how-to-run-rc-local-in-container/8043/7 "2017-12-21T21:22:41Z")

</div>

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