Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM python:3.6.10-alpine3.11 as builder

RUN apk update && apk add --no-cache git build-base mariadb-connector-c-dev
RUN apk add --no-cache --virtual .build-deps openssl-dev gcc musl-dev python3-dev libffi-dev jpeg-dev make mariadb-dev \
&& mkdir /etc/supervisor.d

RUN git clone https://github.com/stacklens/django_blog_tutorial.git --depth=1 /blog && cd /blog && git pull && rm -rf /blog/db.sqlite3

RUN pip install --upgrade pip \
&& pip install wheel \
&& pip wheel -r /blog/requirements.txt --wheel-dir=/pippacks/wheels \
&& pip wheel gunicorn bootstrap4 --wheel-dir=/pippacks/wheels \
&& apk del .build-deps


FROM python:3.6.10-alpine3.11

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

WORKDIR /blog/

RUN apk update \
&& apk add --no-cache nginx bash git libjpeg

COPY --from=builder /pippacks /pippacks
COPY --from=builder /blog /blog

RUN pip install --no-index --find-links=/pippacks/wheels -r requirements.txt \
&& pip install gunicorn bootstrap4 --no-index --find-links=/pippacks/wheels \
&& rm -rf /pippacks

ADD default.conf /etc/nginx/conf.d/default.conf
ADD entrypoint.sh /entrypoint.sh

RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
21 changes: 21 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# django-blog with docker

run with docker

```shell
docker run -d --restart=always --name=blog \
-p 8088:80 \
willdockerhub/django-blog
```

create superuer

```shell
docker exec -it blog python manage.py createsuperuser --username admin
```


accee browers
```
http://192.168.1.1:8088
```
18 changes: 18 additions & 0 deletions docker/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
server {
charset utf-8;
listen 80;
server_name _; # 改成你的 IP

location /static {
alias /blog/collected_static;
}

location /media {
alias /blog/media;
}

location / {
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8000;
}
}
19 changes: 19 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

set -e

# init nginx
if [ ! -d /run/nginx ]; then
mkdir -p /run/nginx
chown -R nginx.nginx /run/nginx
fi

# init blog
if [ ! -f /blog/db.sqlite3 ]; then
python manage.py collectstatic
python manage.py makemigrations
python manage.py migrate
fi

nginx
gunicorn --workers=2 --bind=0.0.0.0:8000 my_blog.wsgi:application