How to make Docker Compose wait for container X before starting Y?
You can make Docker Compose wait for a container X to be fully up and running before starting container Y by using the
depends_on option in your
depends_on option allows you to specify dependencies between services. By default, Docker Compose starts all services simultaneously, but you can use
depends_on to specify that a service should wait for another service to be fully up and running before starting.
Here is an example
docker-compose.yml file that shows how to use the
In this example, we have two services,
depends_on option is used to specify that
service-y should wait for
service-x to be fully up and running before starting. This means that Docker Compose will start
service-x first and wait for it to be fully up and running before starting
Note that the
depends_on option does not guarantee that the dependent service is fully up and running, it only waits for the container to be started. It is recommended to use a health check to make sure that the dependent service is fully up and running before starting the dependent service.
What's the difference between Docker Compose vs. Dockerfile ?
Docker Compose and Dockerfile are two tools that are often used together in Docker-based application development, but they serve different purposes. Dockerfile Dockerfile is used to define the envi...Questions
How Do I Pass Environment Variables to Docker Containers?
It is always a good practice to separate the app from its configuration. It is not a good idea to have a database login credential defined as variables in the code of the application. This is why w...Questions
How to Start Docker Containers Automatically After a Reboot?
Docker provides restart policies to control whether your containers start automatically when they exit, or when Docker restarts. Restart policies ensure that linked containers are started in the co...Questions
How to Copy Files from Docker Container to Host?
Before Docker 1.8, we could only copy files from the container to the host. However, as containers became even more popular, copying files to and from containers has become necessary. One of the re...Questions
Make your mark
Join the writer's program
Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.Write for us
Build on top of Better Stack
Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our firstname.lastname@example.org
or submit a pull request and help us build better products for everyone.
See the full list of amazing projects on github