by Kai Wang, TA from last year
When you install the PostgreSQL in your VM, it will by default create a server in your localhost and also create a database named postgres
and a user named postgres
. After acknowledging that, you could configure the database by default in your settings.py as below form:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'HOST': '',
'PORT': 5432,
}
}
The empty HOST
field means your localhost. And you could add more database and user as well as changing database configuration. But please notice that it will only change your local database server.
Professor Brian will elaborate more about container and Docker in class. This note will only explain why we add 'web' to ALLOWED_HOSTS, how to change the database settings while running the program inside docker and how to debug in docker.
When you firstly use the command sudo docker-compose up
, it will build the image and then run the service (docker container). Docker-compose is a tool for defining and running multi-container Docker applications.
And let's have a look of docker-compose for Assignment 1.
Take service web-init
for example. Let us go through the service configuration line by line.
build: ./web-app
it configures the option to appeared at build time. Simply speaking, in the build time, the Dockerfile in the ./web-app will be built to an image.
command: /code/initserver.sh
it is similar to CMD
in the Dockerfile, it provides defaults command for an executing container. So the command
here means execute initserver.sh when start running a container.
`volumes:
./web-app:/code`
it maps the directory './web-app' to the volume '/code' inside docker (check it in Dockerfile). That means it will overlay the /code folder in the container with whatever is in the './web-app' directory at the time of docker-compose up.
`depends_on:
db`
it expresses dependency between services. when using 'docker-compose up', it starts services in dependency order, so db
is started before web-init
.
For more information please refer to Docker document and docker-compose document.