Build postgres docker container with initial schema

前端 未结 2 2077
温柔的废话
温柔的废话 2020-12-13 00:26

I\'m looking to build dockerfiles that represent company databases that already exist. Similarly, I\'d like create a docker file that starts by restoring a psql dump.

<
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-13 01:06

    According to the usage guide for the official PostreSQL Docker image, all you need is:

    Dockerfile

    FROM postgres
    ENV POSTGRES_DB my_database
    COPY psql_dump.sql /docker-entrypoint-initdb.d/
    

    The POSTGRES_DB environment variable will instruct the container to create a my_database schema on first run.

    And any .sql file found in the /docker-entrypoint-initdb.d/ of the container will be executed.

    If you want to execute .sh scripts, you can also provide them in the /docker-entrypoint-initdb.d/ directory.

提交回复
热议问题