skip to Main Content

I am currently facing a problem with docker, docker-compose, and postgres that is driving me insane. I have updated my docker-compose with a new postgres password and I have updated my sqlalchemy create_all method with a new table model. But none of these changes are taking affect.

When I go to login to the database container it is still using the old password and the table columns have not been updated. I have run all the docker functions I can think of to no avail

docker-compose down --volumes
docker rmi $(docker images -a -q)
docker system prune -a
docker-compose build --no-cache

After running these commands I do verify that the docker image is gone. I have no images or containers living on my machine but the new postgres image still always is created using the previous password. Below is my docker-compose (I am aware that passwords in docker-compose files is a bad idea, this is a personal project and I intend to change it to pull a secret from KMS down the road)

   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

The password commented out under POSTGRES_DB: rebindme is the one that it is still using somehow. I can post more code or whatever else is needed, just let me know. Thanks in advance for your help!

2

Answers


  1. Chosen as BEST ANSWER

    The answer ended up being that the images were still existing. The below command did not actually remove all containers just unused ones:

    docker system prune -a
    

    I did go ahead and delete the postgres data as Pooya recommended though I am not sure that was necessary as I had already done that which I forgot to mention. The real solution for me was:

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

    Then finally the new config for postgres took.


  2. Because you mount volume manually (Host volumes) and when using docker-compose down --volumes actually docker doesn’t remove volume. If you don’t need to volume and you want to remove that you have to delete this folder (It depends on the operation system) and then run docker-compose

    Command docker-compose down -v just remove below volumes type:

    • Named volumes
    • Anonymous volumes
    # Linux operation system
    rm -rf ./postgres-data
    
    docker-compose build --no-cache
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search