4

I have the following docker-compose part

postgres:
    container_name: postgres
    image: postgres
    environment:
      POSTGRES_PASSWORD: "postgres"
    ports:
      - "15432:5432"
    volumes:
      - /root/database:/var/lib/postgresql/data
    networks:
      - production-network
    restart: unless-stopped
    depends_on:
      - rest-proxy
      - broker

What should I do to run a .sql file and restore the db as soon as I run docker-compose ?

3

1 Answer 1

4

Based on the docker image documentation you can include initialization scripts if you mount under /docker-entrypoint-initdb.d. It should work with both *.sql, *.sql.gz, or *.sh. So in your example, the compose file should look something like this:

postgres:
    container_name: postgres
    image: postgres
    environment:
      POSTGRES_PASSWORD: "postgres"
    ports:
      - "15432:5432"
    volumes:
      - /root/database:/var/lib/postgresql/data
      - /root/database-init/init-user-db.sql:/docker-entrypoint-initdb.d/init-user-db.sql:ro
    networks:
      - production-network
    restart: unless-stopped
    depends_on:
      - rest-proxy
      - broker

Assuming that init-user-db.sql file contains your initialization scripts.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.