docker-compose.yml
version: "3.8"
services:
DB:
image:mysql ← I want to write an image that inputs initial data here
environment:
MYSQL_ROOT_PASSWORD:password
ports:
-port
....
....
....
....
image: mysql ← I want to write an image with initial data input here
Upload the image to Docker Hub or Github Packages You can use the test data in any environment as long as you specify the image by the above method.
From the Dockerfile of the image that inputs the initial data in the first place
Dockerfile
FROM mysql
ENV MYSQL_ROOT_PASSWORD=Password ← I was angry without this
COPY sql file path/docker-entrypoint-initdb.d
The copy part here also says "There is no sql file! I was angry. It seems that you can write a Dockerfile with a relative path from a certain hierarchy
Build this and push it to Github Packages. Here is [Official of Github Packages](https://docs.github.com/en/free-pro-team@latest/packages/using-github-packages-with-your-projects-ecosystem/configuring-docker-for -use-with-github-packages) I think you can follow!
This time I uploaded it to Github Packages so it looks like this
docker-compose.yml
version: "3.8"
services:
DB:
image: docker.pkg.github.com/username/repository name/image name:tag
environment:
MYSQL_ROOT_PASSWORD:password
ports:
-port
....
....
....
....
So, when you actually launch the container It will fall brilliantly.
So
docker-compose up -d
Where it was launched in
docker-compose up
I decided to launch it and take a look.
Then the sql file was permission denied
.
So, mess around with permissions in the Dockerfile.
Dockerfile
FROM mysql
ENV MYSQL_ROOT_PASSWORD=password
COPY sql file path/docker-entrypoint-initdb.d
RUN chown mysql:mysql /docker-entrypoint-initdb.d/*.sql
Now build and push again If you doker-compose.yml with image specified, `` `docker-compose up -d```
The data was wonderfully included! !! !!
https://www.xlsoft.com/jp/blog/blog/2019/10/09/post-7617/ https://github.com/docker-library/postgres/issues/722
Recommended Posts