I have an application that I want to run in a container, and a database that I want to run in a container. I have implemented the database part like so.
db:
image: mysql:5.7
ports:
- "3306:3306"
command: --init-file /SCHEMA.sql
restart: always
environment:
MYSQL_DATABASE: shapeshop
MYSQL_USER: admin
MYSQL_PASSWORD: admin
MYSQL_ROOT_PASSWORD: root
networks:
- backend
My initial schema for my database is in a file called SCHEMA.sql in the same directory as my docker-compose file.
I am using the
command --init-file
configuration to setup up the databse.
When I run docker-compose up it fails with this error :
2021-05-14T08:20:59.320203Z 0 [ERROR] mysqld: File '/SCHEMA.sql' not found (Errcode: 2 - No such file or directory)
Is my command file specified correctly?
volumes:to map the host file into the container, the database startup can't see it. You'd typically mount the SQL file into/docker-entrypoint-initdb.d/and the standardmysqlimage startup will execute it for you (only the first time the container starts).