gpt4 book ai didi

python - Docker 组合安装卷不起作用

转载 作者:行者123 更新时间:2023-12-02 18:18:32 31 4
gpt4 key购买 nike

docker-compose down不是 -v 或 --volume,
并重建 docker-compose up -d --build
新的 PostgreSQL 容器中没有数据。

奇怪的是,如您所见,我还有另一个卷persistent_vol,它运行良好。

这是我的 docker-compose.yml

# the version of Docker-compose
version: "3"

services:
app:
build:
context: .
ports:
- "8000:8000"
volumes:
- ./app:/app
- persistent_vol:/vol/web
command: >
sh -c "python manage.py runserver 0.0.0.0:8000"
environment:
- DB_HOST=db
- DB_NAME=americanos
- DB_USER=postgres
- DB_PASS=supersecretpassword
depends_on:
- db

db:
image: postgres:11-alpine
volumes:
- db_vol:/vol/db
environment:
- POSTGRES_DB=americanos
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=supersecretpassword

volumes:
persistent_vol:
db_vol:

这是检查 db docker 容器。
"Mounts": [
{
"Type": "volume",
"Name": "americanos-project_db_vol",
"Source": "/var/lib/docker/volumes/americanos-project_db_vol/_data",
"Destination": "/vol/db",
"Driver": "local",
"Mode": "rw",
"RW": true,
"Propagation": ""
},
{
"Type": "volume",
"Name": "27b655ba943c50d63af79584f764bd3944b0918ceb299621a5f0e80562fc9638",
"Source": "/var/lib/docker/volumes/27b655ba943c50d63af79584f764bd3944b0918ceb299621a5f0e80562fc9638/_data",
"Destination": "/var/lib/postgresql/data",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
}
],

我错过了什么?

最佳答案

套装/vol/dbPGDATA环境变量或将卷路径更改为 /var/lib/postgresql/data因为 postgres 默认数据文件在 /var/lib/postgresql/data .
https://hub.docker.com/_/postgres

  db:
image: postgres:11-alpine
volumes:
- db_vol:/vol/db
environment:
- POSTGRES_DB=americanos
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=supersecretpassword
- PGDATA=/vol/db # added

或者
  db:
image: postgres:11-alpine
volumes:
- db_vol:/var/lib/postgresql/data # changed
environment:
- POSTGRES_DB=americanos
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=supersecretpassword

关于python - Docker 组合安装卷不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59808009/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com