docker-compose.yml
file. (You can use either a .yml
or .yaml
extension for this file.)Dockerfile
in your project directory.Dockerfile
, see the Docker user guide and the Dockerfile reference.Dockerfile
.Dockerfile
starts with a Python 3 parent image.The parent image is modified by adding a new code
directory. The parent image is further modifiedby installing the Python requirements defined in the requirements.txt
file.Dockerfile
.requirements.txt
in your project directory.RUN pip install -r requirements.txt
command in your Dockerfile
.requirements.txt
file.docker-compose.yml
in your project directory.docker-compose.yml
file describes the services that make your app. In this example those services are a web server and database. The compose file also describes which Docker images these services use, how they link together, any volumes they might need to be mounted inside the containers. Finally, the docker-compose.yml
file describes which ports these services expose. See the docker-compose.yml
reference for more information on how this file works.db
service and the web
service.Note:This uses the build in development server to run your applicationon port 8000. Do not use this in a production environment. For moreinformation, see Django documentation.
docker-compose.yml
file.django-admin startproject composeexample
in a container, using the web
service’s image and configuration. Becausethe web
image doesn’t exist yet, Compose builds it from the currentdirectory, as specified by the build: .
line in docker-compose.yml
.web
service image is built, Compose runs it and executes thedjango-admin startproject
command in the container. This commandinstructs Django to create a set of files and directories representing aDjango project.docker-compose
command completes, list the contents of your project.django-admin
created areowned by root. This happens because the container runs as the root user.Change the ownership of the new files.django-admin
. List the files just to verify this.composeexample/settings.py
file.DATABASES = ...
with the following:docker-compose.yml
.8000
onyour Docker host. On Docker Desktop for Mac and Docker Desktop for Windows, goto http://localhost:8000
on a web browser to see the Djangowelcome page.Note:On certain platforms (Windows 10), you might need to editALLOWED_HOSTS
insidesettings.py
and add your Docker host name or IP address to the list.For demo purposes, you can set the value to:This value is not safe for production usage. Refer to theDjango documentation for more information.
docker ps
or docker container ls
command.Ctrl-C
in the same shell in where youstarted it:rm -rf django
).