【发布时间】:2021-10-24 16:13:15
【问题描述】:
如何将我的 postgreSQL 数据库容器与我的 django 应用程序连接起来。
如何在构建映像时在 postgreSQL 中创建数据库,但情况是我有单独的 postgreSQL 容器,在这种情况下如何连接我的 postgreSQL。
Dockerfile
FROM ubuntu
ENV PATH="/scripts:${PATH}"
RUN apt update -y
RUN apt-get install debconf-utils
RUN apt install python3.8 -y
RUN apt install python3-pip -y
RUN echo 'tzdata tzdata/Areas select Asia' | debconf-set-selections
RUN echo 'tzdata tzdata/Zones/Asia select Kolkata' | debconf-set-selections
RUN DEBIAN_FRONTEND="noninteractive" apt install -y tzdata
RUN apt-get install -y gdal-bin
RUN apt-get install -y libgdal-dev
COPY ./requirements.txt /requirements.txt
RUN pip install -r requirements.txt
RUN mkdir /app
COPY ./app /app
WORKDIR /app
COPY ./scripts /scripts
RUN chmod +x /scripts/*
# RUN mkdir -p /vol/web/media
# RUN mkdir -p /vol/web/static
# RUN mkdir -p /vol/web/media
# RUN adduser --disabled-password user
# RUN chown -R user:user /vol
# RUN chmod -R 755 /vol/web
# USER user
CMD ["entrypoint.sh"]
docker-compose.yml
version: '3.8'
services:
app:
build:
context: .
environment:
- SECRET_KEY=changeme
- ALLOWED_HOSTS=127.0.0.1,localhost
depends_on:
- db
db:
image: postgres
restart: always
volumes:
- static_data:/static/db
ports:
- 5432:5432
container_name: ae73234b58e8
proxy:
build:
context: ./proxy
volumes:
- static_data:/vol/static
ports:
- 80:8080
depends_on:
- app
volumes:
static_data:
所以,我需要在构建Dockerfile 图像时创建一个数据库,我该怎么做?
【问题讨论】:
-
您遇到的确切错误是什么?你的
DATABASES配置是什么样的? -
在
db部分设置凭证环境,与django db设置相同 -
@AKX 和 Amin 我已经更改了问题,请帮帮我!
-
您仍然没有显示确切的错误,或者您的 Django DATABASES 设置。
标签: python django postgresql docker containers