Force container to wait for another container

Hi, I am fairly new to docker.
I have several containers, one of them being a network container that creates a network to which the other containers attach.
On “compose up” time everything works nicely, thanks to the depens_on condition in the docker compose file. But when the system reboots everything breaks.
I know that depens_on is just called on the creation of the containers and not in running time, but I really need some way to delay the start of some containers to let the network container do its things.
Right now, after every reboot, I have to manually log into my server and restart the containers that depend on the network one. I know I could create a script, but is there something more elegant built directly into docker that can do the trick?
Thank you very much

I don’t think there is any in-built delay in Docker.

If you use existing Docker images, you might check their entrypoint script and command.

Example nginx has a simple default command in Dockerfile:

CMD ["nginx", "-g", "daemon off;"]

So you can probably use something like this in compose:

command: sh -c "sleep 10 && exec nginx -g 'daemon off;'"

This issue comes up from time to time and there is no way to wait with starting the container until the main container and its network is created. The example shared by @bluepuma77 only works if one process depends on another, but it doesn’t help with depending on another container’s network namespace. At least I assume this is what you mean by “creates a network to which the other containers attach.”, otherwise the network would be created before the container and all containers woul attach to it the same way.

So the way is a script or creating each container as a systemd service.

I understand the issue, but I don’t remember when I relied on previously created network namespaces before when using docker compose in production, although I remember I used the process namespace of other containers which should be a very similar issue.

I know that issues with the restart policy were reported as well, but I have to ask: Do you have restart policy on “always” That is what should make sure the container is restarted even if it failed since that is not a compose feature but docker daemon feature, but namespace dependencies could be handled differently as it is not about a failing process in the container but failing to start the container in the first place.