Docker PostgreSQL Database Permission Denied

37 views Asked by At

I try to create super user on docker bulid i face problem db issue

This is my code database config

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'smart_home_iot',
        'USER': 'enigma',
        'PASSWORD': '123',
        'HOST': '0.0.0.0',
        'PORT': '5432',
    }
}

if env.str("DATABASE_URL", default=None):
    DATABASES = {
        'default': env.db()
    }

    db_from_env = dj_database_url.config(conn_max_age=600)
    DATABASES['default'].update(db_from_env)

This is my docker file

FROM python:3.8-buster AS build

RUN pip install pipenv
# Copy dependency management files and install app packages to /.venv
COPY ./Pipfile ./Pipfile.lock /
RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy


FROM python:3.8-buster AS release
ARG SECRET_KEY

# Set Working directory
WORKDIR /opt/webapp

# Add runtime user with respective access permissions
RUN groupadd -r django \
  && useradd -d /opt/webapp -r -g django django \
  && chown django:django -R /opt/webapp
USER django
RUN chown django:django -R /opt/webapp
# Copy virtual env from build stage
COPY --chown=django:django --from=build /.venv /.venv
ENV PATH="/.venv/bin:$PATH"

# Copy app source
COPY --chown=django:django . .

# Collect static files and serve app
RUN python3 manage.py collectstatic --no-input
CMD waitress-serve --port=$PORT smart_home_41612.wsgi:application

I try to create super user on docker bulid i face problem db issue

OperationalError at /superuser/create/ connection to server at "postgres" (172.19.0.3), port 5432 failed: FATAL: password authentication failed for user "enigma"

Request Method: POST Request URL: http://0.0.0.0:8000/superuser/create/ Django Version: 2.2.6 Python Executable: /.venv/bin/python Python Version: 3.8.17 Python Path: ['/opt/webapp', '/.venv/bin', '/usr/local/lib/python38.zip', '/usr/local/lib/python3.8', '/usr/local/lib/python3.8/lib-dynload', '/.venv/lib/python3.8/site-packages', '/opt/webapp', '/.venv/lib/python3.8/site-packages/odf', '/.venv/lib/python3.8/site-packages/odf', '/.venv/lib/python3.8/site-packages/odf', '/.venv/lib/python3.8/site-packages/odf', '/.venv/lib/python3.8/site-packages/odf', '/.venv/lib/python3.8/site-packages/odf', '/.venv/lib/python3.8/site-packages/odf']

0

There are 0 answers