Hilscher Community Forum
[SOLVED] Starting services/commands/scripts at startup of a container - Printable Version

+- Hilscher Community Forum (https://forum.hilscher.com)
+-- Forum: netPI 3 - Docker featuring Industrial Raspberry Pi 3 platform (https://forum.hilscher.com/forum-1.html)
+--- Forum: Software (https://forum.hilscher.com/forum-5.html)
+--- Thread: [SOLVED] Starting services/commands/scripts at startup of a container (/thread-185.html)



[SOLVED] Starting services/commands/scripts at startup of a container - Jonas.Sellmann@outlook.de - April-27th-2018

Hello,

how can I start services or commands at the startup of the container. I tried the command field in advanced options, but then the container doesn't start right.

Thanks in advance,

Jonas


Answer - Armin@netPI - April-27th-2018

What commands exactly to you mean? Portainer.io in the used version 1.12.4 on netPI does not offer you all docker commands.

The command field in portainer is this one "docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]"

Thx
Armin


Answer - Jonas.Sellmann@outlook.de - May-4th-2018

I tried to start a python script at the startup of the container. For that I put it in the rc.local but after every startup the script hasn't been executed. Then I tried to start it with the command field, but I don't know if it's possible to specify it there.

Thanks
Jonas


Answer - Armin@netPI - May-7th-2018

Hello Jonas,

you have to dig into the details of Docker technology to understand that rc.local and similar things do not work in a container. You have to take care of all such automatic start commands yourself.

Even if you specify a command like you tried the container will start the ENTRYPOINT command that has been specified by us when we have created the container image. All our example containers are starting the file entrypoint.sh that is in the /etc/init.d folder.

There are two methods to start you own commands:

1.) You make you own private container and do not use you example any more and make changes in the entrypoint.sh file in accordance to your ideas or use any other file when the container image is built.

2.) You use the existing container and specify a different Entry Point file in the web browser GUI when you Add a Container. Then this file is used instead of our default file entrypoint.sh.

Thx
Armin




Answer - Jonas.Sellmann@outlook.de - May-8th-2018

Hello Armin,

I fixed it by starting the python script inside the entrypoint.sh.
Thank you for your help.


RE: [SOLVED] Starting services/commands/scripts at startup of a container - WalterSchaefer - March-9th-2021

Hello, Armin.
I use hilschernetpi/netpi-netx-programming-examples:latest image and want to add my application to container startup.
At the image settings, I see, that entry point is: /usr/sbin/sshd -D.
When I add the container, I have to specify an entry point, "/etc/init.d/entrypoint.sh" (for example). But in your image there is no /etc/init.d/entrypoint.sh. The container is not able to start, if I point to non-existing file.
I solve the problem in the next way:
1. Create container from your image with default entry point
2. Create /etc/init.d/entrypoint.sh
3. Create image from that container
4. Create container from new image and entry point = /etc/init.d/entrypoint.sh

That works, but I think this is not the best solution.
Can you suggest a shorter way?

Thank you,
Walter.


RE: [SOLVED] Starting services/commands/scripts at startup of a container - Armin@netPI - March-9th-2021

Hello Walter,

yes what you see is 100% correct and intended.

Since the "programming example" container shall only show customers how to program the netX chip it does not need any specific start script where usually a lot of processes are started. 

This is why I decided not to implement any start script but just starting the SSH daemon as one any only thread using this construct:

ENTRYPOINT ["/usr/sbin/sshd", "-D"]

So there is an entrypoint defined ... but instead of starting a script it starts a single application SSH with the option "-D" to start it as background service. This is all you need. No additional enterypoint script is necessary at all.

Thx
Armin


RE: [SOLVED] Starting services/commands/scripts at startup of a container - WalterSchaefer - March-9th-2021

(March-9th-2021, 08:19 AM)Armin@netPI Wrote: Hello Walter,

yes what you see is 100% correct and intended.

Since the "programming example" container shall only show customers how to program the netX chip it does not need any specific start script where usually a lot of processes are started. 

This is why I decided not to implement any start script but just starting the SSH daemon as one any only thread using this construct:

ENTRYPOINT ["/usr/sbin/sshd", "-D"]

So there is an entrypoint defined ... but instead of starting a script it starts a single application SSH with the option "-D" to start it as background service. This is all you need. No additional enterypoint script is necessary at all.

Thx
Armin

Armin, I want to use your image and want to add my application to startup.
Is my sequence correct, or there is a shoter way to implement my task?


RE: [SOLVED] Starting services/commands/scripts at startup of a container - Armin@netPI - March-9th-2021

Ah now I got your point.

Well I personally would do it differently, but I am a developer of course ... I would make a copy of the original source code of the container which is located here https://github.com/HilscherAutomation/netPI-netx-programming-examples and would do all my edits in this new source code respository and would then finally let Docker hub generate a complete new container. But this requires of course a Docker Hub account and a Guthub account.

If you do not have neither nor accounts then indeed the only chance is the 4 steps procedure you described. Since many customer do not want to make their source code open to everybody like we do ... they have usually a private server with a private github repository and a private Docker repository. This is how I do it at home. 

Our source code examples never can be so good to meet all the customer demands all at once. This is why we call those containers just examples customers can adapt.

Thx
Armin


RE: [SOLVED] Starting services/commands/scripts at startup of a container - WalterSchaefer - March-9th-2021

(March-9th-2021, 08:42 AM)Armin@netPI Wrote: Ah now I got your point.

Well I personally would do it differently, but I am a developer of course ... I would make a copy of the original source code of the container which is located here https://github.com/HilscherAutomation/netPI-netx-programming-examples and would do all my edits in this new source code respository and would then finally let Docker hub generate a complete new container. But this requires of course a Docker Hub account and a Guthub account.

If you do not have neither nor accounts then indeed the only chance is the 4 steps procedure you described. Since many customer do not want to make their source code open to everybody like we do ... they have usually a private server with a private github repository and a private Docker repository. This is how I do it at home. 

Our source code examples never can be so good to meet all the customer demands all at once. This is why we call those containers just examples customers can adapt.

Thx
Armin
Thank you.
Walter.