When composer runs first time docker compose -f docker-compose-dev.yaml up --build
, it throws DB connection error, but subsequent run does not. That's is, press ctrl+c
to abort the run. Run same command again, it will not give error. So my question is why first time it throws error but not on subsequent runs. Here is my Dockerfile
and docker-compose.yml.
file. To reproduce the error, delete volume and DB container. Run command, it will again throw the error. Even when I run script as it is given in (Part 8: Use Docker Compose) under (Get Started) of Docker documentation, it shows same error.
Dockerfile
#syntax=docker/dockerfile:1
FROM node:18-alpine
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --production
COPY . .
CMD ["node", "src/index.js"]
docker-compose.yml
services:
sgweb:
build:
context: .
ports:
- 3000:3000
depends_on:
- sgdb
environment:
- MYSQL_HOST=sgdb
- MYSQL_USER=root
- MYSQL_PASSWORD=password
- MYSQL_DB=get-started-build
sgdb:
image: mysql:8.0
volumes:
- db-get-started:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=get-started-build
volumes:
db-get-started:
Tried depends_on
, placed DB block first, deep dived syslog to find out the issue, and many more, but no result.