Whenever I run docker-compose up -d --build
to start working on my project, it started up my environment just fine up until yesterday.
Upon running docker-compose up -d --build
, I get this annoying error that says: ERROR: Service 'app' depends on service 'db' which is undefined.
I'm not sure how this is happening out of no where as I've made absolutely no changes whatsoever to the docker-compose.yml
file. I've tried troubleshooting this extensively but to no avail.
What's wrong with my file?
Here's my docker-compose.yml
file:
version: "3.7"
services:
app:
build:
args:
user: sammy
uid: 1000
context: ./
dockerfile: Dockerfile.dev
working_dir: /var/www/
environment:
- COMPOSER_MEMORY_LIMIT=-1
depends_on:
- db
volumes:
- ./:/var/www
networks:
- lahmi
myApp:
image: mysql:5.7
environment:
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_USER: ${DB_USERNAME}
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- dbdata:/var/lib/mysql
- ./docker-compose/mysql/my.cnf:/etc/mysql/my.cnf
- ./docker-compose/mysql/init:/docker-entrypoint-initdb.d
ports:
- 3307:3306
networks:
- lahmi
nginx:
image: nginx:alpine
ports:
- 8005:80
depends_on:
- db
- app
volumes:
- ./:/var/www
- ./docker-compose/nginx:/etc/nginx/conf.d/
networks:
- lahmi
networks:
lahmi:
driver: bridge
volumes:
dbdata:
driver: local
CodePudding user response:
There is no service named db
in docker-compose.yml
. Changing db
to myApp
(database service) may work.
If you are referencing the database as db
in service app
, you must use links configuration to change myApp
to db
or change service name myApp
to db
.
https://docs.docker.com/compose/compose-file/compose-file-v3/#links