How can I automaticly start a service within an existing docker container
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., 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.
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
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
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.
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
I still donât understand this part so I hope someone will come to help you
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.
I know. This is why I started my previous post with
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.
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!).
Port=0 is for the PXE server inside the container
Pi-hole is running bare metal as it need the port to be 53
You said use systems to start the service
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.
and whats that going to do, the container has internet
thats not going to start the service
Can somebody please help me
Does nobody know how to automatically start a service in a socket container
Flagging replies as off-topic is not going to get you any help.
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
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 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.
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
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!
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
Sorry it does turn out that I can remove port=0 with no issues
so everything can run bare metal