Docker-Compose: Provide Postgres password


#1

docker-compose:

version: '3'
services:
    postgres:
        image: postgres:9.5.12
        environment:
            - POSTGRES_PASSWORD=pass
            - POSTGRES_USER=user
            - POSTGRES_DB=db
        ports:
            - 5432:5432
        volumes:
            - ../db:/var/lib/postgresql/data
    
    redis:
        image: redis:3.0-alpine
        restart: always

    redash:
        build: redash/redash:latest
        ports:
            - "5000:5000"
        depends_on:
            - postgres
            - redis
        environment:
            PYTHONUNBUFFERED: 0
            REDASH_LOG_LEVEL: "INFO"
            REDASH_REDIS_URL: "redis://redis:6379/0"
            REDASH_DATABASE_URL: "postgres://user@postgres/db"
            REDASH_COOKIE_SECRET: veryverysecret
            REDASH_WEB_WORKERS: 4
        restart: always
        command: server

    worker:
        build: redash/redash:latest
        command: scheduler
        environment:
            PYTHONUNBUFFERED: 0
            REDASH_LOG_LEVEL: "INFO"
            REDASH_REDIS_URL: "redis://redis:6379/0"
            REDASH_DATABASE_URL: "postgres://user@postgres/db"
            QUEUES: "queries,scheduled_queries,celery"
            WORKERS_COUNT: 2
        restart: always

How do I supply the password to postgres database.

worker_1    | [2018-07-17 07:40:28,553][PID:1][ERROR][MainProcess] Task redash.tasks.refresh_queries[da234160-2373-48c0-859b-151d3426590d] raised unexpected: OperationalError('(psycopg2.OperationalError) fe_sendauth: no password supplied\n',)
worker_1    | Traceback (most recent call last):
worker_1    |   File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 240, in trace_task
worker_1    |     R = retval = fun(*args, **kwargs)
worker_1    |   File "/app/redash/worker.py", line 71, in __call__
worker_1    |     return TaskBase.__call__(self, *args, **kwargs)
worker_1    |   File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 438, in __protected_call__
worker_1    |     return self.run(*args, **kwargs)
worker_1    |   File "/app/redash/tasks/queries.py", line 275, in refresh_queries
worker_1    |     for query in models.Query.outdated_queries():
worker_1    |   File "/app/redash/models.py", line 906, in outdated_queries
worker_1    |     for query in queries:
worker_1    |   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 2797, in __iter__
worker_1    |     return self._execute_and_instances(context)
worker_1    |   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 2818, in _execute_and_instances
worker_1    |     close_with_result=True)
worker_1    |   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 2827, in _get_bind_args
worker_1    |     **kw
worker_1    |   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 2809, in _connection_from_session
worker_1    |     conn = self.session.connection(**kw)
worker_1    |   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 966, in connection
worker_1    |     execution_options=execution_options)
worker_1    |   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 971, in _connection_for_bind
worker_1    |     engine, execution_options)
worker_1    |   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 403, in _connection_for_bind
worker_1    |     conn = bind.contextual_connect()
worker_1    |   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 2103, in contextual_connect
worker_1    |     self._wrap_pool_connect(self.pool.connect, None),
worker_1    |   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 2142, in _wrap_pool_connect
worker_1    |     e, dialect, self)
worker_1    |   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1456, in _handle_dbapi_exception_noconnection
worker_1    |     exc_info
worker_1    |   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/util/compat.py", line 202, in raise_from_cause
worker_1    |     reraise(type(exception), exception, tb=exc_tb, cause=cause)
worker_1    |   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 2138, in _wrap_pool_connect
worker_1    |     return fn()
worker_1    |   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py", line 387, in connect
worker_1    |     return _ConnectionFairy._checkout(self)
worker_1    |   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py", line 766, in _checkout
worker_1    |     fairy = _ConnectionRecord.checkout(pool)
worker_1    |   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py", line 516, in checkout
worker_1    |     rec = pool._do_get()
worker_1    |   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py", line 1138, in _do_get
worker_1    |     self._dec_overflow()
worker_1    |   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/util/langhelpers.py", line 60, in __exit__
worker_1    |     compat.reraise(exc_type, exc_value, exc_tb)
worker_1    |   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py", line 1135, in _do_get
worker_1    |     return self._create_connection()
worker_1    |   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py", line 333, in _create_connection
worker_1    |     return _ConnectionRecord(self)
worker_1    |   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py", line 461, in __init__
worker_1    |     self.__connect(first_connect_check=True)
worker_1    |   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py", line 651, in __connect
worker_1    |     connection = pool._invoke_creator(self)
worker_1    |   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/strategies.py", line 105, in connect
worker_1    |     return dialect.connect(*cargs, **cparams)
worker_1    |   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/default.py", line 392, in connect
worker_1    |     return self.dbapi.connect(*cargs, **cparams)
worker_1    |   File "/usr/local/lib/python2.7/dist-packages/psycopg2/__init__.py", line 164, in connect
worker_1    |     conn = _connect(dsn, connection_factory=connection_factory, async=async)
worker_1    | OperationalError: (psycopg2.OperationalError) fe_sendauth: no password supplied

#2

You change the Postgres URL to:

postgres://user:pass@postgres/db

#3

That works. Thanks.

A minor query, If I keep the docker container service name as postgres all works good, if i change it to something say db it breaks the deployment,

worker_1 | [2018-07-17 06:55:57,616][PID:1][ERROR][MainProcess] Task redash.tasks.refresh_queries[91974663-8e8c-48e5-923d-72919f6cfe90] raised unexpected: NoSuchModuleError("Can't load plugin: sqlalchemy.dialects:db",)

I think internally they are using the container name to identify the datasource they want to connect to