Reputation: 53
I am getting the following error when I run docker-compose up:
Thanks a lot for your help
Upvotes: 1
Views: 23469
Reputation: 51
I had the same issue, however, my problem occurred due to Linux user. I am using root as a runner so the problem happened because the mounting volume in the local machine did not have permissions. in this regard, I used chmod -R 777 scripts
and it worked fine. Technically, you need to set permissions for both local machine and your container.
Upvotes: 5
Reputation: 81
I resolved this problem by adding this to the Dockerfile after it copies the scripts to docker-entrypoint-initdb.d
RUN chown -R mysql:mysql /docker-entrypoint-initdb.d/
Example Dockerfile:
FROM mysql:latest
ENV MYSQL_DATABASE NAME_DATABASE
ENV MYSQL_ROOT_PASSWORD ***********
COPY ./sql-scripts/ /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"]
The next step is to build the image:
docker build -t image-db:latest .
The next step is to create the container
docker run -d -p 3306:3306 --name container-db image-db:latest
Upvotes: 8
Reputation: 1701
You should not override the postgres image entrypoint. It is designed to look for .sql
files in /docker-entrypoint-initdb.d/
directory (See line in script).
You should just mount your .sql
files into /docker-entrypoint-initdb.d/
and it should be processed on startup (only if database does not already exist)
Upvotes: 3