I'm trying to start 3 docker containers in a sequential order using the docker-compose. I have the following containers:
- app-service-db container -> Database
- config-service container -> Spring boot application
- app-service container -> Spring boot application
I want the ' app-service ' container to start only when the other two containers have finish starting. I'm using the ' wait-for ' script to wait for the services to become available (https://github.com/Eficode/wait-for).
Here is what I have inside the docker-compose.yml
version: '3.4'
services:
config-service:
image: "config-service:1.0"
hostname: config-service
container_name: config-service
build:
context: ../config
dockerfile: config.dockerfile
expose:
- "8888"
logging:
driver: json-file
app-service-db:
image: "app-service-db:10.3"
hostname: app-service-db
container_name: app-service-db
build:
context: ../app-service
dockerfile: app-db.dockerfile
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: app
expose:
- "3306"
logging:
driver: json-file
app-service:
image: "app-service:1.0"
hostname: app-service
container_name: app-service
build:
context: ../app-service
dockerfile: app.dockerfile
ports:
- "8080:8080"
expose:
- "8080"
logging:
driver: json-file
command: sh -c './wait-for app-service-db:3306 && config-service:8888'
depends_on:
- config-service
- app-service-db
config.dockerfile
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ADD target/config-1.0-final.jar config.jar
ENTRYPOINT ["java", "-jar", "config.jar"]
EXPOSE 8888
app-db.dockerfile
FROM mariadb:10.3
app.dockerfile
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ADD target/app-1.0-final.jar app.jar
ENTRYPOINT ["java", "-jar", "app.jar"]
EXPOSE 8080
When I run the ' docker-compose up ' cmd the ' app-service ' container is starting before the ' app-service-db ' and ' config-service ' have finished and is exited because it can't find any connection. How can I make this work and force the ' app-service ' container to start only when the other two containers have started.
Thanks in advance.