from Quail4789@lemmy.ml to selfhosted@lemmy.world on 03 Nov 07:53
https://lemmy.ml/post/22088904
I have some of my Docker containers bind to Tailscale IPs on the host. Even though I edited the Docker service to depend on tailscaled.service and it starts about 10 seconds after it, every once in a while Tailscale interface won’t be ready by the time the containers try to spin up after a reboot.
Since restart
policies do not apply to containers that has never started and ran at least for a while, Docker gives me no choice but to restart either those containers or the Docker daemon manually.
Is there a way to have Docker daemon try to restart containers even though they failed on the first try?
A restart policy only takes effect after a container starts successfully. In this case, starting successfully means that the container is up for at least 10 seconds and Docker has started monitoring it. This prevents a container which doesn’t start at all from going into a restart loop.
https://docs.docker.com/engine/containers/start-containers-automatically
#selfhosted
threaded - newest
I’m happy with autoheal: github.com/willfarrell/docker-autoheal
Delay the start of your containers with the tailscale dependency. Are you using required or depends_on in your docker-compose.yml
hatchjs.com/docker-compose-conditionally-start-se…
If you’re using kubernetes you can make the requirements at the pod level
stackoverflow.com/…/container-initialization-orde…
Edit: If using docker-compose.yml you can set a condition on a healthcheck
You can also specify a condition that must be met before the service is started. For example, the following configuration will start the
web
service only if thedb
service is healthy:The
service_healthy
condition checks the health of thedb
service using thedocker-compose ps
command. If thedb
service is healthy, theweb
service will be started.You probably want to look into Health Checks. I believe you can tell Docker to “start service B when service A is healthy”, so you can define your health check with a script that depends on Tailscale functioning.
I need to figure this out on my immich stack. VM reboot only starts two out of the 4 services. Ty for the info.
This is the correct answer, but you need a few things to clarify:
Considering it’s tailscale, one may want to have the service fail though as tailscale is sometimes not used for convenience but security concerns instead.