This lab teaches you how to use Visual Studio Code's Docker extension to build a Docker container for an existing Django web application which takes log messages and stores them in an SQLite database.
The container that you use in this lab will be used in other labs that teach you how to publish a Docker container.
If you're doing this lab outside of the Microsoft booth at PyCon 2019, you'll need the following tools installed on your local machine:
-
Open the lab folder with Visual Studio Code:
cd 1-vscode-django-docker code-insiders .
-
Run
Ctrl-Shift-P
and typeAdd Docker files to Workspace
. -
Following the prompts select
Python
and port8000
. -
Change the RUN and CMD lines in the Dockerfile to the following:
# Using pip: RUN python3 -m pip install -r requirements.txt RUN python3 manage.py migrate CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]
-
Right-click on docker-compose.yml and click
Compose up
. -
Open http://localhost:8000 in the browser to view the app.
If you want to build a container using a production webserver using nginx and uwsgi, you can follow the steps below.
The application already contains a uwsgi.ini
file which defines how to run the web server,
so you only need to make some small modifications to the Dockerfile.
-
Remove the CMD line from the Dockerfile.
-
Change the FROM line to:
FROM tiangolo/uwsgi-nginx
-
Replace the EXPOSE line with
ENV LISTEN_PORT=8000
-
Right-click on docker-compose.yml and click
Compose up
. -
Open http://localhost:8000 in the browser to view the app.