Launch Docker image with initial data injected with docker-compose

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! !! !!

Reference article

https://www.xlsoft.com/jp/blog/blog/2019/10/09/post-7617/ https://github.com/docker-library/postgres/issues/722

Recommended Posts

Launch Docker image with initial data injected with docker-compose
Start SQL Server with Docker & register initial data
Launch MariaDB with Docker
Run lambda with custom docker image
[Rails] Initial data creation with seed
Create Laravel environment with Docker (docker-compose)
Restart apache with docker php-apache image
Initial data input with [Rails] seed_fu!
Build apache7.4 + mysql8 environment with Docker (with initial data) (your own memo)
Run (provisionally) a Docker image with ShellCommandActivity on AWS Data Pipeline
Proxy server with squid using docker image
Launch Nginx + Spring Boot application with docker-compose
[Among Us] Launch automuteus v4.0.4 with docker-compose
Allow image posting with [Docker + WordPress + MySQL]
Image flew when updating Docker with WSL2
I tried to verify AdoptOpenJDK 11 (11.0.2) with Docker image
How to give your image to someone with docker
Update container image with KUSANAGI Runs on Docker
I can't do docker-compose up -d with docker
EC2 ✕ Manual deployment with Docker / docker-compose / Asset compilation
Until you try running Apache Kafka with docker image
Setup with initial test data inserted in Db2 / DB container
Save image data with AWS_S3 + Ruby on Rails_Active Storage
Build an Android image for Orange Pi 4 with Docker
[Rails] Create initial data with seed.rb [Faker] [Japanese localization]