-
Notifications
You must be signed in to change notification settings - Fork 8.1k
update postgres initialization for compose/django.md #10624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,23 +60,31 @@ and a `docker-compose.yml` file. (You can use either a `.yml` or `.yaml` extensi | |
| expose. See the [`docker-compose.yml` reference](/compose/compose-file/index.md) for more | ||
| information on how this file works. | ||
|
|
||
| 9. Add the following configuration to the file. | ||
| 9. Add the following configuration to the file. | ||
|
|
||
| ```none | ||
| version: '3' | ||
|
|
||
| services: | ||
| db: | ||
| image: postgres | ||
| web: | ||
| build: . | ||
| command: python manage.py runserver 0.0.0.0:8000 | ||
| volumes: | ||
| - .:/code | ||
| ports: | ||
| - "8000:8000" | ||
| depends_on: | ||
| - db | ||
| # docker-compose.yml | ||
|
|
||
| version: '3' | ||
|
|
||
| services: | ||
| db: | ||
| image: postgres | ||
| ports: #add line. | ||
|
||
| - '5432' | ||
| environment: # add line. | ||
| - POSTGRES_DB=postgres | ||
| - POSTGRES_USER=postgres | ||
| - POSTGRES_PASSWORD=postgres | ||
| web: | ||
| build: . | ||
| command: python manage.py runserver 0.0.0.0:8000 | ||
| volumes: | ||
| - .:/code | ||
| ports: | ||
| - "8000:8000" | ||
| depends_on: | ||
| - db | ||
| ``` | ||
|
|
||
| This file defines two services: The `db` service and the `web` service. | ||
|
|
@@ -138,21 +146,24 @@ In this section, you set up the database connection for Django. | |
|
|
||
| 1. In your project directory, edit the `composeexample/settings.py` file. | ||
|
|
||
| 2. Replace the `DATABASES = ...` with the following: | ||
|
|
||
| DATABASES = { | ||
| 'default': { | ||
| 'ENGINE': 'django.db.backends.postgresql', | ||
| 'NAME': 'postgres', | ||
| 'USER': 'postgres', | ||
| 'HOST': 'db', | ||
| 'PORT': 5432, | ||
| } | ||
| } | ||
|
|
||
| These settings are determined by the | ||
| [postgres](https://hub.docker.com/_/postgres) Docker image | ||
| specified in `docker-compose.yml`. | ||
| 2. Replace the `DATABASES = ...` with the following: | ||
|
|
||
| # setting.py | ||
|
|
||
| DATABASES = { | ||
| 'default': { | ||
| 'ENGINE': 'django.db.backends.postgresql', | ||
| 'NAME': 'postgres', | ||
| 'USER': 'postgres', | ||
| 'PASSWORD': 'postgres', #add line. | ||
|
||
| 'HOST': 'db', | ||
| 'PORT': 5432, | ||
| } | ||
| } | ||
|
|
||
| These settings are determined by the | ||
| [postgres](https://hub.docker.com/_/postgres) Docker image | ||
| specified in `docker-compose.yml`. | ||
|
|
||
| 3. Save and close the file. | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, remove this comment line. The previous steps already mention the filename.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay