# Docker start service

**URL:** <https://forums.docker.com/t/docker-start-service/125024>\
**Category:** General\
**Created:** [May 28, 2022, 10:11am UTC](https://forums.docker.com/t/docker-start-service/125024 "2022-05-28T10:11:58Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jackcox2312](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/jackcox2312/32/32498_2.png) [@jackcox2312](https://forums.docker.com/u/jackcox2312)\
**Post date:** [May 28, 2022, 10:11am UTC](https://forums.docker.com/t/docker-start-service/125024/1 "2022-05-28T10:11:58Z")

</div>

How can I automaticly start a service within an existing docker container

---

<div class="post-metadata">

**Author:** ![rimelek](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/rimelek/32/41602_2.png) [@rimelek](https://forums.docker.com/u/rimelek)\
**Post date:** [May 29, 2022, 12:12pm UTC](https://forums.docker.com/t/docker-start-service/125024/2 "2022-05-29T12:12:04Z")

</div>

The point of Docker containers is that you have an isolated environment for usually one process and its children. Docker containers are not for traditional services running in the background. You run the container in detached mode (in the background) and inside the container you run the process in the foreground and it will keep the container alive.

Packages installed from package repositories like APT are usually not compatible with this concept, so you need to run those processes yourself. You can use for example [Supervisord.](http://supervisord.org/), but if you really want to run containers and still use Systemd to start your services, you can use LXD on Linux instead of Docker or use virtual machines.

Yes, it is possible to run systemd in a Docker container, but it does not make sense for me, except for testing.

---

<div class="post-metadata">

**Author:** ![jackcox2312](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/jackcox2312/32/32498_2.png) [@jackcox2312](https://forums.docker.com/u/jackcox2312)\
**Post date:** [May 29, 2022, 2:18pm UTC](https://forums.docker.com/t/docker-start-service/125024/3 "2022-05-29T14:18:28Z")

</div>

If you knew my use of docker you would understand why it’s my only option

I am using a raspberry pi 4 and I am running Pi-hole on it, docker is running dnsmasq for a PXE boot server but after every reboot, I made it automatically start the container but I still have to type “service dnsmasq start” after every boot up

Virtual machines do not work well on raspberry pi

Edit: I thought I probably mention that Pi-hole uses it’s own dnsmasq so if I sent the port to 0 it dosnt work. So docker gives it a separate up address

---

<div class="post-metadata">

**Author:** ![rimelek](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/rimelek/32/41602_2.png) [@rimelek](https://forums.docker.com/u/rimelek)\
**Post date:** [May 29, 2022, 7:16pm UTC](https://forums.docker.com/t/docker-start-service/125024/4 "2022-05-29T19:16:34Z")

</div>

> [@jackcox2312](#):
>
> If you knew my use of docker you would understand why it’s my only option

I wrote about multiple solutions. Virtual machines was one of them only for running systemd but you don’t need systemd, only dnsmasq and you can run it without the service command. The service command just executes a predefined command to run it in the background which you usually don’t want unless you have a process that keeps the container alive and in addition to that you want an other process running in the background. I guess this is what you want, but it was not completely clear after reading your last post either. Try to be very specific so our answers can be that too.

For example I don’t know just guess that you want to run dnsmasq in a container that also runs Pi-hole. There is a Docker image for that: [pihole/pihole](https://hub.docker.com/r/pihole/pihole)

Maybe you are already using it, you just didn’t mention it. That image uses an init system similar to Supervisord. It is s6-init which has its own configuration but the concept is the same. You run one init process that can start other processes and handles signals like “TERM” to properly stop every process.

Do you use this pihole image I linked above? It is an important detail to know before we can help.

If you use this image, check its description on Docker Hub if you have not done it yet.

---

<div class="post-metadata">

**Author:** ![jackcox2312](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/jackcox2312/32/32498_2.png) [@jackcox2312](https://forums.docker.com/u/jackcox2312)\
**Post date:** [May 30, 2022, 10:39am UTC](https://forums.docker.com/t/docker-start-service/125024/5 "2022-05-30T10:39:29Z")

</div>

> [@rimelek](#):
>
> For example I don’t know just guess that you want to run dnsmasq in a container that also runs Pi-hole. There is a Docker image for that: [pihole/pihole](https://hub.docker.com/r/pihole/pihole)

and that is impossible because you can not have port=0  
my pihole is not the problem, the PXE server is  
and I said I can’t use virtual machines because raspberry pi 4

and systemd dosn’t work in docker because the system has not booted with systemd

---

<div class="post-metadata">

**Author:** ![rimelek](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/rimelek/32/41602_2.png) [@rimelek](https://forums.docker.com/u/rimelek)\
**Post date:** [May 30, 2022, 9:36pm UTC](https://forums.docker.com/t/docker-start-service/125024/6 "2022-05-30T21:36:40Z")

</div>

> [@jackcox2312](#):
>
> and that is impossible because you can not have port=0

I still don’t understand this part so I hope someone will come to help you

> [@jackcox2312](#):
>
> my pihole is not the problem, the PXE server is

I may have misunderstood that but you miss the point. You need an init process/process manager that handles multiple services in one container if you want to start multiple process in one container. That process manager must be the first process which start everything else. Now you need to choose one. During our discussion I wrote 3 of them. The fact that the “system has not booted with systemd” is irrelevant here. First of all this is the only one that I do not even recommend to use and you probably mean “systemctl” does not work, not “systemd”. Systemd could work, the recent versions also supporrt the environment variable “container” with the value “docker” it is a Docker container but it needs to be run as the first process inside the container. But I emphesize again: this is the only process manager I don’t recommend s lets’s forget it.

So you have two other optons that you can choose from this topic and you may find other process managers too. S6 and Supervisor are the two that I know.

> [@jackcox2312](#):
>
> and I said I can’t use virtual machines because raspberry pi 4

I know. This is why I started my previous post with

> [@rimelek](#):
>
> I wrote about multiple solutions. Virtual machines was one of them

and only for the case that is not your case, using Systemd. So let’s forget about virtual machines too, since I understood you immediately after your first post about that.

I hope I could clarify the misunderstandings. Again, the point is that you need S6 or Supervisor or an equivalent process manager.

---

<div class="post-metadata">

**Author:** ![meyay](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/meyay/32/34000_2.png) [@meyay](https://forums.docker.com/u/meyay)\
**Post date:** [May 31, 2022, 5:59am UTC](https://forums.docker.com/t/docker-start-service/125024/7 "2022-05-31T05:59:53Z")

</div>

I must admit, so far the situation is still ambigous.

Responses can be as good as the questions/provided details, idealy in the first post!

I am still unclear on:

- is pihole running bare metal or inside a container?
  - if pihole is run inside a container, which image is used?
  - if pihole is run inside a container, is dnsmasq provided by the image used or a different dnsmasq running in a different container?
  - If pihole is run inside a container, does it use `--network=host` to use the network namespace of the host and therefor act network-wise as every native process on the host?

- what is “port=0” supposed to be? All ports? Multicast?
- also please share the exact command (or compose file) used to create the container(s), as it will give us details you might miss to mention otherwise

Please provide all relevant details to enable us to fully understand your situation and get an idea of what should be solved (the big picture and not the problem of the minute please!).

---

<div class="post-metadata">

**Author:** ![jackcox2312](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/jackcox2312/32/32498_2.png) [@jackcox2312](https://forums.docker.com/u/jackcox2312)\
**Post date:** [May 31, 2022, 9:07am UTC](https://forums.docker.com/t/docker-start-service/125024/8 "2022-05-31T09:07:10Z")

</div>

Port=0 is for the PXE server inside the container  
Pi-hole is running bare metal as it need the port to be 53

---

<div class="post-metadata">

**Author:** ![jackcox2312](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/jackcox2312/32/32498_2.png) [@jackcox2312](https://forums.docker.com/u/jackcox2312)\
**Post date:** [May 31, 2022, 9:07am UTC](https://forums.docker.com/t/docker-start-service/125024/9 "2022-05-31T09:07:52Z")

</div>

> [@rimelek](#):
>
> The fact that the “system has not booted with systemd” is irrelevant here

You said use systems to start the service

---

<div class="post-metadata">

**Author:** ![meyay](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/meyay/32/34000_2.png) [@meyay](https://forums.docker.com/u/meyay)\
**Post date:** [May 31, 2022, 2:50pm UTC](https://forums.docker.com/t/docker-start-service/125024/10 "2022-05-31T14:50:58Z")

</div>

Judged by the details shared so far, the only thing I can recommend is to check wether `--network=host` is a valid option for your dnsmasq container.

Appart from that there is not much to work with. I hope you do find a solution for what you try to do and share the result in this thread for the rest of the world to benefit from.

---

<div class="post-metadata">

**Author:** ![jackcox2312](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/jackcox2312/32/32498_2.png) [@jackcox2312](https://forums.docker.com/u/jackcox2312)\
**Post date:** [June 1, 2022, 10:02am UTC](https://forums.docker.com/t/docker-start-service/125024/11 "2022-06-01T10:02:56Z")

</div>

> [@meyay](#):
>
> Judged by the details shared so far, the only thing I can recommend is to check wether `--network=host` is a valid option for your dnsmasq container.

and whats that going to do, the container has internet  
thats not going to start the service

---

<div class="post-metadata">

**Author:** ![jackcox2312](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/jackcox2312/32/32498_2.png) [@jackcox2312](https://forums.docker.com/u/jackcox2312)\
**Post date:** [June 3, 2022, 9:57am UTC](https://forums.docker.com/t/docker-start-service/125024/12 "2022-06-03T09:57:35Z")

</div>

Can somebody please help me

---

<div class="post-metadata">

**Author:** ![jackcox2312](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/jackcox2312/32/32498_2.png) [@jackcox2312](https://forums.docker.com/u/jackcox2312)\
**Post date:** [June 7, 2022, 10:21pm UTC](https://forums.docker.com/t/docker-start-service/125024/13 "2022-06-07T22:21:21Z")

</div>

Does nobody know how to automatically start a service in a socket container

---

<div class="post-metadata">

**Author:** ![avbentem](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@avbentem](https://forums.docker.com/u/avbentem)\
**Post date:** [June 8, 2022, 5:33am UTC](https://forums.docker.com/t/docker-start-service/125024/14 "2022-06-08T05:33:24Z")

</div>

Flagging replies as off-topic is not going to get you any help. 👎

---

<div class="post-metadata">

**Author:** ![jackcox2312](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/jackcox2312/32/32498_2.png) [@jackcox2312](https://forums.docker.com/u/jackcox2312)\
**Post date:** [June 10, 2022, 9:28pm UTC](https://forums.docker.com/t/docker-start-service/125024/15 "2022-06-10T21:28:47Z")

</div>

Well it was off topic  
The answer was unrelated to the question

–network=host is clearly to do with network not starting a service

and I am not happy with how this is going  
every time I need help, I don’t get it  
thats why I stopped using docker, but now I need it as its free and more PCs or Raspberry Pi’s are not free

And I do not appreciate that from a moderator, a mod should help not say I am wrong for marking it as off topic when it is off topic

---

<div class="post-metadata">

**Author:** ![avbentem](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@avbentem](https://forums.docker.com/u/avbentem)\
**Post date:** [June 11, 2022, 6:36am UTC](https://forums.docker.com/t/docker-start-service/125024/16 "2022-06-11T06:36:28Z")

</div>

> every time I need help, I don’t get it

Please understand we’re all just volunteers trying to help, and **you are not helping us to help you**. You’ve got [two of the most active users](https://forums.docker.com/u?order=post_count&period=yearly) being **very patient** to get details from you, in this topic and some of the earlier ones, to understand what you’re trying to achieve. And you’re hardly answering their questions, but instead being hostile towards them and feel you’re not getting any help? 🤯

Aside, as for expecting help, and assuming that at some point you found the solution for your earlier topics: it would be great to share that for future readers as well. So, please add resolutions to your old topics.

And to increase the chances to get help here again, please go over the requests for details above that you did not respond to yet. Or get a paid subscription and see if Docker Inc. is willing to spend the crazy amount of time that @rimelek and @meyay did.

**Any new flag or hostile response from you will get your account banned.**

---

<div class="post-metadata">

**Author:** ![jackcox2312](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/jackcox2312/32/32498_2.png) [@jackcox2312](https://forums.docker.com/u/jackcox2312)\
**Post date:** [June 11, 2022, 7:44pm UTC](https://forums.docker.com/t/docker-start-service/125024/18 "2022-06-11T19:44:17Z")

</div>

If I re-create the container only running one process and replace bash with the process name will it work  
Because I will need to install the process, so the first time I start the container the process won’t exist

---

<div class="post-metadata">

**Author:** ![meyay](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/meyay/32/34000_2.png) [@meyay](https://forums.docker.com/u/meyay)\
**Post date:** [June 11, 2022, 7:44pm UTC](https://forums.docker.com/t/docker-start-service/125024/19 "2022-06-11T19:44:41Z")

</div>

No one is hostile towards you. Your communication style just does not allign with our, The level of details you think are relevant do not satisfy the the details we need to get a big picture and think things thru. It is up to you if you provide enough details and enable someone in actualy understanding your situation. You choose to not provide these details and I choose to stop responding because of that.

The `port=0` issue is what `--network=host` was aimed for. Without this beeing sorted out it does not matter if the “start service” topic is solved. Do we agree on this?

Most people run pihole with `--network=host` AND use the intergrated dnsmasq to provide PXE. What’s wrong with that solution. Not using that solution is what makes you feel that you need to start a service in docker in the first place.

Personaly, I am not a fan to assist someone with the “problem of the minute” because someone tries to force patterns of the non-container world to containers.

So if the objective is to run pihole+dnsmasq to use PXE, then run the pihole image with `--network=host `. If your objective still is to run a service in a container then I would suggest to take a look at how pihole leverages s6-overlay to run their stuff as services.

Good luck!

---

<div class="post-metadata">

**Author:** ![jackcox2312](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/jackcox2312/32/32498_2.png) [@jackcox2312](https://forums.docker.com/u/jackcox2312)\
**Post date:** [June 11, 2022, 7:47pm UTC](https://forums.docker.com/t/docker-start-service/125024/20 "2022-06-11T19:47:52Z")

</div>

> The `port=0` issue is what `--network=host` was aimed for.

That was never the issue you asked why I can’t run dnsmasq and pihole

> Most people run pihole with `--network=host`

And again what did I say, pihole is running bare metal

> use the intergrated dnsmasq to provide PXE

This can not be done as pihole uses port 53 and TFTP needs dns disabled

> If I re-create the container only running one process and replace bash with the process name will it work  
> Because I will need to install the process, so the first time I start the container the process won’t exist

---

<div class="post-metadata">

**Author:** ![jackcox2312](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/jackcox2312/32/32498_2.png) [@jackcox2312](https://forums.docker.com/u/jackcox2312)\
**Post date:** [June 11, 2022, 7:53pm UTC](https://forums.docker.com/t/docker-start-service/125024/21 "2022-06-11T19:53:39Z")

</div>

Sorry it does turn out that I can remove port=0 with no issues  
so everything can run bare metal

[Next page](https://forums.docker.com/t/docker-start-service/125024.md?page=2)
