• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED] Starting services/commands/scripts at startup of a container
#1
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
  Reply
#2
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
You never fail until you stop trying.“, Albert Einstein (1879 - 1955)

  Reply
#3
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
  Reply
#4
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

You never fail until you stop trying.“, Albert Einstein (1879 - 1955)

  Reply
#5
Hello Armin,

I fixed it by starting the python script inside the entrypoint.sh.
Thank you for your help.
  Reply
#6
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.
  Reply
#7
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
You never fail until you stop trying.“, Albert Einstein (1879 - 1955)

  Reply
#8
(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?
  Reply
#9
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/ne...g-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
You never fail until you stop trying.“, Albert Einstein (1879 - 1955)

  Reply
#10
(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/ne...g-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.
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  TOSILOCK for CONTAINER COswald 3 2,183 July-13th-2021, 11:32 AM
Last Post: Armin@netPI
  Access to RTC from my own container application tad 1 3,520 March-19th-2021, 02:58 PM
Last Post: Armin@netPI
  OpenVPN container Armin@netPI 0 1,614 January-3rd-2021, 12:13 PM
Last Post: Armin@netPI
  operating Console of a container on netPI connected to Wi-Fi tethering tad 3 2,611 December-3rd-2020, 12:32 PM
Last Post: tad
  NIOT-E-NPIX-4DI4DO with netpi-netx container WalterSchaefer 3 6,475 November-25th-2020, 01:06 PM
Last Post: zen89
  NPIX-4DI4DO and NetPi-Nodered container issues alhammi 4 7,583 November-16th-2020, 01:35 PM
Last Post: alhammi
  Get host MAC via REST API inside container bschandra 4 3,640 November-16th-2020, 09:26 AM
Last Post: bschandra
  Receive at startup additional data through the Fieldbus Port Schranz 1 2,810 September-10th-2020, 10:55 AM
Last Post: Armin@netPI
  Exporting and importing container images Armin@netPI 3 3,066 May-20th-2020, 11:24 AM
Last Post: COswald
Exclamation Creating a container Linnerz 6 4,429 March-6th-2020, 02:47 PM
Last Post: Armin@netPI

Forum Jump:


Users browsing this thread: 1 Guest(s)