在docker compose中使用https://github.com/kiasaki/docker-alpine-postgres图像时,我从日志中查看时,/ docker-entrypoint.initdb.d中的脚本没有被执行:
db_1 | LOG: database system was shut down at 2016-09-05 18:16:02 UTC
db_1 | LOG: MultiXact member wraparound protections are now enabled
db_1 | LOG: database system is ready to accept connections
db_1 | LOG: autovacuum launcher started
问题是,如果我独立构建Dockerfile并运行容器,它将执行文件夹中的sql文件,就像从日志中看到的那样:
waiting for server to start....LOG: database system was shut down at 2016-09-05 18:28:18 UTC
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
done
server started
/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/syna-setup.sql
CREATE TABLE
INSERT 0 1
CREATE TABLE
waiting for server to shut down...LOG: received fast shutdown request
.LOG: aborting any active transactions
LOG: autovacuum launcher shutting down
LOG: shutting down
LOG: database system is shut down
done
server stopped
LOG: database system was shut down at 2016-09-05 18:28:21 UTC
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
LOG: received fast shutdown request
LOG: aborting any active transactions
LOG: autovacuum launcher shutting down
LOG: shutting down
LOG: database system is shut down
docker-compose.yml:
version: '2'
services:
db:
build: ./db
environment:
- POSTGRES_PASSWORD=testpass
restart: always
app:
build: ./app
ports:
- "5000:5000"
volumes:
- .:/app/src
depends_on:
- db
environment:
- DB_SERVER=postgres://postgres:testpass@db:5432/postgres
我在这里做错了什么?
答案 0 :(得分:0)
UPDATED ,因为他使用自己的Dockerfile,而不是使用github链接。
你能不能使用docker run命令来mkdir /docker-entrypoint-initdb.d
。您应该将一些目录安装到容器中,以便它可以找到SQL文件。
我在https://github.com/kiasaki/docker-alpine-postgres/blob/master/Dockerfile读了Dockerfile并问自己SQL文件在哪里?它只是使目录没有复制SQL文件
docker-entrypoint.sh
然后,在for f in /docker-entrypoint-initdb.d/*; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.sql) echo "$0: running $f"; psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < "$f" && echo ;;
*) echo "$0: ignoring $f" ;;
esac
echo
done
中,检查是否有任何要执行的SQL文件
version: '2'
services:
db:
build: ./db
environment:
- POSTGRES_PASSWORD=testpass
restart: always
entrypoint:
- docker-entrypoint.sh
volumes:
- ./docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
- ./docker-entrypoint.sh:/docker-entrypoint.sh
我认为我们应该挂载一个SQL目录,比如
10 action * 20 videos for each * (500*350)
features = input for SVM for training