Multiple containers with autostart and dependencies?

jdesai61
New here
Posts: 8
Joined: Mon Aug 15, 2016 4:43 am

Multiple containers with autostart and dependencies?

Postby jdesai61 » Mon Aug 15, 2016 5:00 am

I am using Container Station on TS453A with latest software. I have two containers - cntr1 and cntr2. The container cntr2 is dependent on cntr1 (in Advanced Settings for cntr2, there is a link to cntr1). I would like both containers to auto-start. However, when QNAP reboots (or container station restarts), the container cntr2 doesn't start most of the time (sometime both containers will properly auto-start). The error from docker.log file is:

docker.log:time="2016-08-14T10:48:25.294704840-04:00" level=error msg="Handler for POST /v1.22/containers/79c38c1d6f5a1f049d541354cbe84854e9d36c41c6a94d7dfdb0b7aedd7fea2d/start returned error: Cannot link to a non running container: /cntr1 AS /cntr2/cntr1"

Is there any way to wait for starting the cntr2 - so it will wait for cntr1 to start?

Thanks in advance.

lab221
Starting out
Posts: 11
Joined: Sat Sep 10, 2016 4:07 pm

Re: Multiple containers with autostart and dependencies?

Postby lab221 » Sun Sep 11, 2016 2:39 pm

Hi,

Maybe using docker-compose with depends_on option is the better way to control the order of service startup.
https://docs.docker.com/compose/compose-file/#/depends-on

Thanks.

jdesai61
New here
Posts: 8
Joined: Mon Aug 15, 2016 4:43 am

Re: Multiple containers with autostart and dependencies?

Postby jdesai61 » Sun Nov 20, 2016 10:44 pm

Thank you very much. I will try that out.

horiz
Starting out
Posts: 12
Joined: Sat Sep 17, 2016 8:41 pm

Re: Multiple containers with autostart and dependencies?

Postby horiz » Wed Apr 19, 2017 12:29 am

Hey guys,
did you have any success with docker compose?
Do you have any other tips to share?

Thanks

jdesai61
New here
Posts: 8
Joined: Mon Aug 15, 2016 4:43 am

Re: Multiple containers with autostart and dependencies?

Postby jdesai61 » Wed Apr 19, 2017 1:14 am

I did not try docker compose. However, I ended up solving this problem by binding the container (cntr1 in above example) port to host port and then checking for port accessibility on the second (cntr2) container. So for example bind MySQL port # (3306) in cntr1 to a host port (e.g. 13306) and then from cntr2, I use wait-for-it (https://github.com/vishnubob/wait-for-it) to check for availability of port 13306 on the host before I start my application. This works for me because both containers are running on the same host and it is simpler - plus even if I use compose, I would need wait-for-it script anyways because compose only guarantees that cntr1 is started before cntr2 - it does not guarantee availability of services on the container(s).
Also, for me the advantage of binding to host port is that I don't need to know the IP address of the other container (which is likely to change). YMMV - especially if your containers run on multiple hosts.
Hope this helps.

filipeff12
New here
Posts: 3
Joined: Thu Nov 09, 2017 6:12 am

Re: Multiple containers with autostart and dependencies?

Postby filipeff12 » Tue Nov 14, 2017 10:03 pm

Hi,
I'm trying to do the same thing, but I didn't fully understand how you used that scrip.

Did you put the script inside the second container and run it from there? (how did you do that )

How did you automate that script run, so that on every boot that script runs ?

jdesai61
New here
Posts: 8
Joined: Mon Aug 15, 2016 4:43 am

Re: Multiple containers with autostart and dependencies?

Postby jdesai61 » Sun Aug 12, 2018 4:46 am

Sorry this is probably too late a response, but for copying the file to the second container I ended up creating my own Dockerfile and adding following to the Dockerfile (wait_and_run.sh is my script to check for available ports)

ADD wait_and_run.sh /tmp/
RUN chmod +x /tmp/wait_and_run.sh
ENTRYPOINT /tmp/wait_and_run.sh

And then ENTRYPOINT command actully ensures that scripts runs at startup.


Return to “Container Station”

Who is online

Users browsing this forum: No registered users and 0 guests