我目前面临着docker、docker compose和postgres的问题,这让我抓狂。我用一个新的postgres密码更新了我的docker-compose,并用一个新表模型更新了sqlalchemiccreate_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 composes文件中的密码是个坏主意,这是一个个人项目,我打算改变它,从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 system prune -a
我确实按照Pooya的建议删除了postgres数据,尽管我不确定这是否有必要,因为我已经做了,但我忘了提及。对我来说,真正的解决方案是:
docker image ls
docker rmi rebindme-client:latest
docker rmi rebindme-api:latest
然后,postgres的新配置终于实现了。
如果出现问题,请连接postgres映像并将行插入表,但不更新表
1( 放下所有容器:码头工人组成
2( 删除所有卷:码头数量rm$(码头数量ls-q(
3( 删除要发布的相关容器:docker镜像rm容器名称
因为您手动装载卷(主机卷(,并且当使用docker-compose down --volumes
时,docker实际上不会删除卷。如果你不需要卷,你想删除,你必须删除这个文件夹(这取决于操作系统(,然后运行docker compose
命令docker-compose down -v
只是删除以下卷类型:
- 命名卷
- 匿名卷
# Linux operation system
rm -rf ./postgres-data
docker-compose build --no-cache