Answer the question
In order to leave comments, you need to log in
How can i execute script.sql in a container???
I have a LAMP project and I'm trying to run it in Docker compose. The application is running but has no connection to mysql. Cause: sql file is not executed and the database is not created. When I enter the container and manually run the sql file, everything then works well.
FROM mysql:5.7.17
ENV MYSQL_ROOT_PASSWORD password123
COPY script.sql /docker-entrypoint-initdb.d/
RUN chown -R mysql:mysql /docker-entrypoint-initdb.d/
EXPOSE 3306
CMD ["mysqld", "--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci"]
Answer the question
In order to leave comments, you need to log in
Complicated. It makes no sense to customize the image, just mount the script.sql directory in docker-entrypoint-initdb.d:
volumes:
- ./init:/docker-entrypoint-initdb.d
use <db_name>
(where <db_name>
the database is freshly created), and then the actual list of requests. And yes, all this does not happen instantly - it is necessary to provide in the application a check that the database has completely risen, some kind of delay to come up with ... command:
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question