【发布时间】:2022-01-04 22:25:31
【问题描述】:
我目前正面临着一个让我发疯的 docker、docker-compose 和 postgres 问题。我已经用新的 postgres 密码更新了我的 docker-compose,并用新的表模型更新了我的 sqlalchemy create_all 方法。但这些更改都没有生效。
当我登录数据库容器时,它仍在使用旧密码,并且表列尚未更新。我已经运行了所有我能想到的 docker 功能,但无济于事
docker-compose down --volumes
docker rmi $(docker images -a -q)
docker system prune -a
docker-compose build --no-cache
运行这些命令后,我确实验证了 docker 映像已消失。我的机器上没有图像或容器,但新的 postgres 图像仍然总是使用以前的密码创建的。下面是我的 docker-compose(我知道 docker-compose 文件中的密码是个坏主意,这是一个个人项目,我打算更改它以从 KMS 中提取秘密)
services:
api:
# container_name: rebindme-api
build:
context: api/
restart: always
container_name: rebindme_api
environment:
- API_DEBUG=1
- PYTHONUNBUFFERED=1
- DATABASE_URL=postgresql://rebindme:password@db:5432/rebindme
# context: .
# dockerfile: api/Dockerfile
ports:
- "8443:8443"
volumes:
- "./api:/opt/rebindme/api:ro"
depends_on:
db:
condition: service_healthy
image: rebindme_api
networks:
web-app:
aliases:
- rebindme-api
db:
image: postgres
container_name: rebindme_db
# build:
# context: ./postgres
# dockerfile: db.Dockerfile
volumes:
- ./postgres-data:/var/lib/postgresql/data
# - ./sql/create_tables.sql:/docker-entrypoint-initdb.d/create_tables.sql
environment:
POSTGRES_USER: rebindme
POSTGRES_PASSWORD: password
POSTGRES_DB: rebindme
#03c72130-a807-491e-86aa-d4af52c2cdda
healthcheck:
test: ["CMD", "psql", "postgresql://rebindme:password@db:5432/rebindme"]
interval: 10s
timeout: 5s
retries: 5
restart: always
networks:
web-app:
aliases:
- postgres-network
client:
container_name: rebindme_client
build:
context: client/
volumes:
- "./client:/opt/rebindme/client"
# - nodemodules:/node_modules
# ports:
# - "80:80"
image: rebindme-client
networks:
web-app:
aliases:
- rebindme-client
nginx:
depends_on:
- client
- api
image: nginx
ports:
- "80:80"
volumes:
- "./nginx/default.conf:/etc/nginx/conf.d/default.conf"
- "./nginx/ssl:/etc/nginx/ssl"
networks:
web-app:
aliases:
- rebindme-proxy
# volumes:
# database_data:
# driver: local
# nodemodules:
# driver: local
networks:
web-app:
# name: db_network
# driver: bridge
POSTGRES_DB: rebindme 下注释掉的密码是它仍在使用的密码。我可以发布更多代码或其他任何需要的内容,请告诉我。提前感谢您的帮助!
【问题讨论】:
-
docker-compose down --volumes之后,您确认./postgres-data中没有文件了吗?这里有一些建议,也许他们有帮助:stackoverflow.com/questions/45891599/…
标签: python-3.x postgresql docker-compose