When I run 3 images through the following docker-compose file.
version: "3.8" services: consumer: image: consumer container_name: docker-consumer ports: - "9098:9098" networks: - producer-consumer depends_on: - producer producer: image: producer container_name: docker-producer ports: - "9090:9090" networks: - producer-consumer depends_on: - mysql mysql: image: mysql:8 container_name: mysql-db ports: - 3306:3306 networks: - producer-consumer environment: - MYSQL_ROOT_PASSWORD=14292 - MYSQL_DATABASE=HR - MYSQL_USER=root networks: producer-consumer:
I have to set up a delay for producer and consumer containers until the MySQL container is created. when I run the above file then MySQL connection is going to be failed with the connection URL.
I am using
container_name instead of using
localhost and during the creation of the producer container it is trying to use
localhost to connect and it will be failed.
can I run the container sequentially in the following way?
Source: Docker Questions