# Https://stackoverflow.com/questions/74866043/sql-script-in-docker-compose-yaml

**URL:** <https://forums.docker.com/t/https-stackoverflow-com-questions-74866043-sql-script-in-docker-compose-yaml/133303>\
**Category:** General\
**Created:** [December 22, 2022, 9:29am UTC](https://forums.docker.com/t/https-stackoverflow-com-questions-74866043-sql-script-in-docker-compose-yaml/133303 "2022-12-22T09:29:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![niteshn2424](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/niteshn2424/32/32506_2.png) [@niteshn2424](https://forums.docker.com/u/niteshn2424)\
**Post date:** [December 22, 2022, 9:29am UTC](https://forums.docker.com/t/https-stackoverflow-com-questions-74866043-sql-script-in-docker-compose-yaml/133303/1 "2022-12-22T09:29:09Z")

</div>

I’d like to run this “amend\_user.sql” script in the database as per below sequence. I just dont know how to do this using docker compose with yaml file. Please advise.

1. Download image & create postgres instance
2. Run the flyway job
3. Execute “amend\_user.sql” in postgres database

In the below example, this script runs as soon as the service starts whereas i would like it to run at the end or after step 2.

```auto
version: '3.8' services:   
 db:
    container_name: postgresDB
    image: postgres:15.1
    restart: always
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=password
    ports:
      - '5432:5432'
    volumes:
      - postgres:/var/lib/postgresql/data
      - ./scripts/amend_user.sql:/docker-entrypoint-initdb.d/amend_user.sql
    build:
      context: .
      dockerfile: dockerfile-db

  flyway_admin:
    image: redgate/flyway:6.6.1
    environment:
      - FLYWAY_USER=postgres
      - FLYWAY_PASSWORD=password
      - FLYWAY_URL=jdbc:postgresql://db:5432/postgres
      - FLYWAY_LOCATIONS=filesystem:/flyway/admin/versions
    command: -connectRetries=60 check
    volumes:
      - ./admin/:/flyway/sql/admin
    depends_on:
      - db

   volumes:   
     postgres:

```

---

<div class="post-metadata">

**Author:** ![meyay](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/meyay/32/34000_2.png) [@meyay](https://forums.docker.com/u/meyay)\
**Post date:** [December 22, 2022, 9:32am UTC](https://forums.docker.com/t/https-stackoverflow-com-questions-74866043-sql-script-in-docker-compose-yaml/133303/2 "2022-12-22T09:32:35Z")

</div>

This seems to be the same post as [How to run sql script in sequence using docker compose](https://forums.docker.com/t/how-to-run-sql-script-in-sequence-using-docker-compose/133229/)

Please do not open more than one topic for the same subject.
