mirror of https://github.com/docker/docs.git
[FIX] update documentation (#13701)
* [FIX] update documentation - add `PYTHONDONTWRITEBYTECODE` environment variable - rename pip package `psycopg2-binary` to `psycopg2` - add db environment variables in docker-compose for a better usage - use `os.environment` in `setting.py` to get environment variables * [fix] update documentation
This commit is contained in:
parent
f5513bd89b
commit
c331fa9929
|
@ -30,6 +30,7 @@ and a `docker-compose.yml` file. (You can use either a `.yml` or `.yaml` extensi
|
||||||
```dockerfile
|
```dockerfile
|
||||||
# syntax=docker/dockerfile:1
|
# syntax=docker/dockerfile:1
|
||||||
FROM python:3
|
FROM python:3
|
||||||
|
ENV PYTHONDONTWRITEBYTECODE=1
|
||||||
ENV PYTHONUNBUFFERED=1
|
ENV PYTHONUNBUFFERED=1
|
||||||
WORKDIR /code
|
WORKDIR /code
|
||||||
COPY requirements.txt /code/
|
COPY requirements.txt /code/
|
||||||
|
@ -50,7 +51,7 @@ and a `docker-compose.yml` file. (You can use either a `.yml` or `.yaml` extensi
|
||||||
6. Add the required software in the file.
|
6. Add the required software in the file.
|
||||||
|
|
||||||
Django>=3.0,<4.0
|
Django>=3.0,<4.0
|
||||||
psycopg2-binary>=2.8
|
psycopg2>=2.8
|
||||||
|
|
||||||
7. Save and close the `requirements.txt` file.
|
7. Save and close the `requirements.txt` file.
|
||||||
|
|
||||||
|
@ -74,10 +75,6 @@ and a `docker-compose.yml` file. (You can use either a `.yml` or `.yaml` extensi
|
||||||
image: postgres
|
image: postgres
|
||||||
volumes:
|
volumes:
|
||||||
- ./data/db:/var/lib/postgresql/data
|
- ./data/db:/var/lib/postgresql/data
|
||||||
environment:
|
|
||||||
- POSTGRES_DB=postgres
|
|
||||||
- POSTGRES_USER=postgres
|
|
||||||
- POSTGRES_PASSWORD=postgres
|
|
||||||
web:
|
web:
|
||||||
build: .
|
build: .
|
||||||
command: python manage.py runserver 0.0.0.0:8000
|
command: python manage.py runserver 0.0.0.0:8000
|
||||||
|
@ -85,6 +82,10 @@ and a `docker-compose.yml` file. (You can use either a `.yml` or `.yaml` extensi
|
||||||
- .:/code
|
- .:/code
|
||||||
ports:
|
ports:
|
||||||
- "8000:8000"
|
- "8000:8000"
|
||||||
|
environment:
|
||||||
|
- POSTGRES_NAME=postgres
|
||||||
|
- POSTGRES_USER=postgres
|
||||||
|
- POSTGRES_PASSWORD=postgres
|
||||||
depends_on:
|
depends_on:
|
||||||
- db
|
- db
|
||||||
```
|
```
|
||||||
|
@ -169,12 +170,16 @@ In this section, you set up the database connection for Django.
|
||||||
```python
|
```python
|
||||||
# settings.py
|
# settings.py
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
[...]
|
||||||
|
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
'default': {
|
||||||
'ENGINE': 'django.db.backends.postgresql',
|
'ENGINE': 'django.db.backends.postgresql',
|
||||||
'NAME': 'postgres',
|
'NAME': os.environ.get('POSTGRES_NAME'),
|
||||||
'USER': 'postgres',
|
'USER': os.environ.get('POSTGRES_USER'),
|
||||||
'PASSWORD': 'postgres',
|
'PASSWORD': os.environ.get('POSTGRES_PASSWORD'),
|
||||||
'HOST': 'db',
|
'HOST': 'db',
|
||||||
'PORT': 5432,
|
'PORT': 5432,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue