0

I am able to run a SQL file as follows:

  1. Setup Dockerfile as:

    FROM mysql

    ENV MYSQL_DATABASE stock_app

    COPY ./sql-scripts/ /docker-entrypoint-initdb.d/

  2. Building the image:

    docker build -t db.

  3. Run the following command:

    docker run -d -p 3306:3306 –name db -e MYSQL_ROOT_PASSWORD=password db

This is working and able to verify that SQL commands inside the script are executed and the table is created.

What changes should I make so that all three steps are done when I do the following command to bring up all my images?

docker-compose up -d

Instead of manually building the image for db and running the command to execute the SQL file, is there an option to place the run SQL file within Dockerfile? That is to include step 3 mentioned above within Dockerfile.