[英]Dockerized Django REST Framework / Postgresql - Disallowed host
When I try to execute the following command: 当我尝试执行以下命令时:
sudo docker-compose up
I get the following error inside my terminal: 我在终端中收到以下错误:
Here is what my docker file looks like: 这是我的docker文件的样子:
FROM python:3.6
ENV PYTHONUNBUFFERED 1
RUN mkdir /agent-technologies
WORKDIR /agent-technologies
COPY . /agent-technologies
RUN pip install -r requirements.txt
EXPOSE 8000
Here is what my docker-compose.yml
looks like: 这是我
docker-compose.yml
样子:
version: '3'
services:
db:
image: postgres
environment:
- POSTGRES_USER=stefan_radonjic
- POSTGRES_PASSWORD=cepajecar995
- POSTGRES_DB=agent_technologies_db
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/agent-technologies
ports:
- "8000:8000"
links:
- db
depends_on:
- db
And finally here are settings of PostgresSQL DB I have previously created : 最后是我之前创建的PostgresSQL DB的设置:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'agent_technologies_db',
'USER': 'stefan_radonjic',
'PASSWORD': 'cepajecar995',
'HOST': 'db',
'PORT': '',
}
}
Your django app is trying to connect to 'localhost' database, but as it is inside its own container -- localhost is not right uri to reach database. 您的django应用正在尝试连接到“本地主机”数据库,但由于它位于其自己的容器内-本地主机不适合访问数据库。
Dockercompose will resolve your namequeries to database if you will refer to is by db container name. 如果您是通过db容器名称引用的,则Dockercompose会将您的名称查询解析为数据库。 In your case it is "db"
您的情况是“ db”
As text on picture reads -- you have to add "0.0.0.0" into your ALLOWED_HOSTS
variable inside your settings module. 阅读图片上的文字时-您必须在设置模块内的
ALLOWED_HOSTS
变量中添加“ 0.0.0.0”。
Be sure that you've read django documentation carefully. 确保您已仔细阅读django文档。 It is pretty vigorous.
它非常有活力。
The error is quite self explanatory.. You didn't set your ip in your ALLOWED_HOSTS setting . 该错误很容易解释。.您未在ALLOWED_HOSTS设置中设置 IP。 Try adding these to your settings file:
尝试将这些添加到您的设置文件:
ALLOWED_HOSTS = ['*'] # wildcard, allows all
Or if you want to be explicit: 或者,如果您想露骨:
ALLOWED_HOSTS = ['0.0.0.0'] # explicit
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.