Search code examples
postgresqldockerdocker-swarm

Docker swarm stack ignores postgres password env variable


I'm trying to deploy postgres and pgadmin as a swarm stack via docker stack deploy with this compose file

version: '3.7'

services:
  postgres:
    image: postgres
    ports:
      - "5432:5432"
    volumes:
      - postgres-data:/var/lib/postgresql/data
    environment:
      - POSTGRES_PASSWORD=87654321
  pgadmin:
    image: dpage/pgadmin4
    ports:
     - "5433:80" 
    environment:
     - [email protected]
     - PGADMIN_DEFAULT_PASSWORD=12345678
    depends_on:
     - postgres 
volumes:
  postgres-data: 

With docker stack deploy - POSTGRES_PASSWORD is never applied to postgres, I can echo env variable inside the container and it contains correct value 87654321 but postgres still uses the default one. However if I use the same compose file with docker-compose everything works fine


Solution

  • I think the volume postgres-data has already all the data required for postgres.

    try to delete it first and re-deploy the stack.

    docker-compose down --remove-orphans --volumes
    

    or stop the stack and run:

    docker volume rm postgres-data