撰写:运行退出的容器

我有一个docker-compose.yml与postgres和一个web应用程序(鬼)。 我想在postgres和ghost之间运行一个容器来初始化postgres,添加一个数据库和用户权限,然后退出。

我的数据库初始化代码如下所示:

ghostdb: extends: file: ./compose/ghost.yml service: ghostdb links: - postgres volumes: - ./ghost-db/volumes/sql:/sql 

反过来运行

 #!/bin/bash echo Importing SQL until pg_isready -h postgres; do sleep 1 done for f in /sql/*.sql; do echo Importing $f psql -h postgres -f $f done 

我知道我可以扩展postgres来添加这个function,但我宁愿将这两个问题分开。 所以我有两个问题:

有初始化数据库的最佳模式? 可以运行一个在postgres和ghost之间退出的容器吗?

完整的存储库可以在这里查看: https : //github.com/devpaul/ghost-compose