【问题标题】:postgres image does no update when I update docker-compose file当我更新 docker-compose 文件时,postgres 图像没有更新
【发布时间】: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 下注释掉的密码是它仍在使用的密码。我可以发布更多代码或其他任何需要的内容,请告诉我。提前感谢您的帮助!

【问题讨论】:

标签: python-3.x postgresql docker-compose


【解决方案1】:

答案最终是图像仍然存在。以下命令实际上并未删除所有容器,只是未使用的容器:

docker system prune -a

我确实按照 Pooya 的建议删除了 postgres 数据,尽管我不确定这是否必要,因为我已经完成了我忘记提及的事情。对我来说真正的解决方案是:

docker image ls
docker rmi rebindme-client:latest
docker rmi rebindme-api:latest

然后终于有了 postgres 的新配置。

【讨论】:

    【解决方案2】:

    因为您手动安装卷(主机卷)并且在使用docker-compose down --volumes 时实际上 docker 不会删除卷。如果你不需要卷并且你想删除你必须删除这个文件夹(这取决于操作系统)然后运行 ​​docker-compose

    命令docker-compose down -v 只需删除以下卷类型:

    • 命名卷
    • 匿名卷
    # Linux operation system
    rm -rf ./postgres-data
    
    docker-compose build --no-cache
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-25
      • 1970-01-01
      • 1970-01-01
      • 2014-08-14
      • 2017-05-05
      • 2020-10-11
      • 1970-01-01
      相关资源
      最近更新 更多