Hello,
I am trying to setup a compose with 3 services:
mysql
prisma (which waits for the mysql service to be healthy before applying migration)
my-app: which is a nextjs app.
I set depends_on section in prisma and my-app to wait for one another before starting.
The issue I am facing is that the app service starts to “build” before its dependencies (mysql and prisma) are finished. I think the design is that app will build ahead of time, then once built wait for the dependencies to be ready, then app will run (CMD).
The problem is that my-app beeing a nextjs app, it needs at build time to already have access to the mysql service with the DB already migrated.
In the current version of docker compose I wonder if it is possible to instruct a service to not only wait for the other services to be ready before starting, but also to even wait before building its image?
In the example below, my app starts to build BEFORE mysql and prisma, which is not desirable
Here is what I have:
services:
mysql:
container_name: mysql
image: mysql:5.7
environment:
MYSQL_DATABASE: $MYSQLDB_DATABASE
MYSQL_ROOT_PASSWORD: $MYSQLDB_PASSWORD
MYSQL_ROOT_HOST: '%'
healthcheck:
test:
[
"CMD",
"mysqladmin",
"ping",
"-h",
"127.0.0.1",
"--silent"
]
interval: 5s
timeout: 5s
retries: 20
ports:
- $MYSQLDB_LOCAL_PORT:$MYSQLDB_DOCKER_PORT
expose:
- $MYSQLDB_DOCKER_PORT
volumes:
- db:/var/lib/mysql
networks:
- app
prisma:
container_name: prisma
depends_on:
mysql:
condition: service_healthy
restart: true
build:
context: .
dockerfile: prisma.Dockerfile
networks:
- app
my-app:
container_name: my-app
depends_on:
mysql:
condition: service_healthy
restart: true
prisma:
condition: service_completed_successfully
restart: true
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped
ports:
- $APP_LOCAL_PORT:$APP_DOCKER_PORT
environment:
- NEXT_TELEMETRY_DISABLED=$NEXT_TELEMETRY_DISABLED
- NEXTAUTH_SECRET=$NEXTAUTH_SECRET
- NEXTAUTH_URL=$NEXTAUTH_URL
networks:
- app
volumes:
db:
networks:
app: {}
Thank you