Skip to content

Commit 68655ef

Browse files
authored
Merge pull request #2 from Microsoft/docker-files
Docker files
2 parents af47407 + 130c3e4 commit 68655ef

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

.dockerignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
node_modules
2+
npm-debug.log
3+
Dockerfile*
4+
docker-compose*
5+
.dockerignore
6+
.git
7+
.gitignore
8+
README.md
9+
LICENSE
10+
.vscode
11+
env

Dockerfile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Pull a pre-built alpine docker image with nginx and python3 installed
2+
FROM tiangolo/uwsgi-nginx:python3.6-alpine3.7
3+
4+
# Set the port on which the app runs; make both values the same.
5+
#
6+
# IMPORTANT: When deploying to Azure App Service, go to the App Service on the Azure
7+
# portal, navigate to the Applications Settings blade, and create a setting named
8+
# WEBSITES_PORT with a value that matches the port here (the Azure default is 80).
9+
# You can also create a setting through the App Service Extension in VS Code.
10+
ENV LISTEN_PORT=8000
11+
EXPOSE 8000
12+
13+
# Indicate where uwsgi.ini lives
14+
ENV UWSGI_INI uwsgi.ini
15+
16+
# Tell nginx where static files live. Typically, developers place static files for
17+
# multiple apps in a shared folder, but for the purposes here we can use the one
18+
# app's folder. Note that when multiple apps share a folder, you should create subfolders
19+
# with the same name as the app underneath "static" so there aren't any collisions
20+
# when all those static files are collected together, as when using Django's
21+
# collectstatic command.
22+
ENV STATIC_URL /app/static_collected
23+
24+
# Copy the app files to a folder and run it from there
25+
WORKDIR /app
26+
ADD . /app
27+
28+
# Make app folder writeable for the sake of db.sqlite3, and make that file also writeable.
29+
# Ideally you host the database somewhere else so that the app folders can remain read only.
30+
# Without these permissions you see the errors "unable to open database file" and
31+
# "attempt to write to a readonly database", respectively, whenever the app attempts to
32+
# write to the database.
33+
RUN chmod g+w /app
34+
RUN chmod g+w /app/db.sqlite3
35+
36+
# Make sure dependencies are installed
37+
RUN python3 -m pip install -r requirements.txt

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
This sample contains the completed program from the tutorial, [Using Django in Visual Studio Code](https://code.visualstudio.com/docs/python/tutorial-django). Intermediate steps are not included.
22

3+
The sample also includes a Dockerfile to build a production-ready container image that uses uwsgi and nginx; the uwsgi.ini file provides uwsgi configuration.
4+
35
To run the sample:
46

57
1. Create a virtual environment as described in the tutorial.

uwsgi.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[uwsgi]
2+
chdir = .
3+
module = web_project.wsgi:application
4+
env = DJANGO_SETTINGS_MODULE=web_project.settings
5+
uid = 1000
6+
master = true
7+
threads = 2
8+
processes = 4

web_project/settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@
2323
SECRET_KEY = '2gult1d96#@#b2%tz+k9x1q%-4(%f@va-!sbv*q&$t^gpp8-_='
2424

2525
# SECURITY WARNING: don't run with debug turned on in production!
26+
# If you set to False, also add "localhost" to ALLOWED_HOSTS or else
27+
# you'll get "Bad Request" when running locally.
2628
DEBUG = True
2729

30+
# When deploying to Azure App Service, add you <name>.azurewebsites.net
31+
# domain to ALLOWED_HOSTS; you get an error message if you forget.
2832
ALLOWED_HOSTS = []
2933

3034

0 commit comments

Comments
 (0)