docker – Why do container replicas fail?

I have a swarm docker environment with two replicas of each service. However, when starting the replicas they fail and the error “task: non-zero exit (255)” is displayed. The error happens several times until the container is started correctly.

Image: Container Initialization History

Image: Error code of a container in the “failed” state

How to solve this problem?