title: Execute SQL script on docker compose
body: <p>I have a project that runs when ./entrypoint.sh or docker-compose up is run from the root directory of project and generates the swagger API interface, but the calls return entry response no data. </p>
  
  <p>If I run with MySQL on localhost without docker, works perfectly fine. How do I load the data? </p>
  
  <p>entrypoint.sh</p>
  
  <pre><code>#!/bin/bash
  
  docker network create turingmysql
  docker container run -p  3306:3306 --name mysqldb --network turingmysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=tshirtshop -d mysql:5.7
  docker-compose build
  docker-compose up
  </code></pre>
  
  <p>DockerFile</p>
  
  <pre><code>FROM mysql:5.7
  
  ADD ./database/tshirtshop.sql /docker-entrypoint-initdb.d
  </code></pre>
  
  <pre><code>#### Stage 1: Build the application
  FROM openjdk:8-jdk-alpine as build
  
  # Set the current working directory inside the image
  WORKDIR /app
  
  # Copy maven executable to the image
  COPY mvnw .
  COPY .mvn .mvn
  
  # Copy the pom.xml file
  COPY pom.xml .
  
  # Build all the dependencies in preparation to go offline. 
  # This is a separate step so the dependencies will be cached unless 
  # the pom.xml file has changed.
  RUN ./mvnw dependency:go-offline -B
  
  # Copy the project source
  COPY src src
  
  
  # Package the application
  RUN ./mvnw package -DskipTests
  RUN mkdir -p target/dependency &amp;&amp; (cd target/dependency; jar -xf ../*.jar)
  
  #### Stage 2: A minimal docker image with command to run the app 
  FROM openjdk:8-jre-alpine
  
  ARG DEPENDENCY=/app/target/dependency
  
  # Copy project dependencies from the build stage
  COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib
  COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF
  COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app
  
  ENTRYPOINT ["java","-cp","app:app/lib/*","com.turing.ecommerce.TuringApplication"]
  </code></pre>
  
  <p>docker-compose.yml</p>
  
  <pre><code>version: '3.7'
  
  # Define services
  services:
    # App backend service
    app-server:
      # Configuration for building the docker image for the backend service
      build:
        context: .
        dockerfile: Dockerfile
      ports:
        - "8080:8080" # Forward the exposed port 8080 on the container to port 8080 on the host machine
      restart: always
      depends_on: 
        - mysqldb # This service depends on mysql. Start that first.
      environment: # Pass environment variables to the service
        SPRING_DATASOURCE_URL: jdbc:mysql://mysqldb:3306/tshirtshop?useSSL=false&amp;useLegacyDatetimeCode=false&amp;serverTimezone=UTC
        SPRING_DATASOURCE_USERNAME: root
        SPRING_DATASOURCE_PASSWORD: root   
      networks: # Networks to join (Services on the same network can communicate with each other using their name)
        - turingmysql
  
        # Database Service (Mysql)
    mysqldb:
      image: mysql:5.7
      ports:
        - "3306:3306"
      restart: always
  
      environment:
        MYSQL_DATABASE: tshirtshop
        MYSQL_USER: root
        MYSQL_ROOT_PASSWORD: root
      volumes:
        - db-data:/var/lib/mysql
  
      networks:
        - turingmysql  
  
  
  # Volumes
  volumes:
    db-data:
  
  # Networks to be created to facilitate communication between containers
  networks:
    turingmysql:
  </code></pre>