Skip to content

Commit 2ba9ab9

Browse files
author
yangxg
committed
Step19: dockerize
1 parent 680a241 commit 2ba9ab9

19 files changed

+231
-30
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.*
2+
_credentials.py
3+
fabfile.py
4+
*.sqlite3

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ venv.bak/
106106
*.sqlite3
107107
media/
108108
_credentials.py
109+
.production
109110

110111
# Pycharm .idea folder, see following link to know which files should be ignored:
111112
# https://www.jetbrains.com/help/pycharm/synchronizing-and-sharing-settings.html#7e81d3cb

.idea/django-blog-tutorial-v2.iml renamed to .idea/HelloDjango-blog-tutorial.iml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[[source]]
22
name = "pypi"
3-
url = "https://pypi.org/simple"
3+
url = "https://pypi.douban.com/simple"
44
verify_ssl = true
55

66
[dev-packages]

Pipfile.lock

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,36 @@ tutorial 分支为项目的主分支,每一篇教程的代码都和历史提
8686

8787
### Docker
8888

89-
即将奉上!敬请期待~
89+
1. **安装 Docker 和 Docker Compose**
90+
91+
2. **克隆项目到本地**
92+
93+
```
94+
git clone https://github.com/HelloGitHub-Team/HelloDjango-blog-tutorial.git
95+
```
96+
97+
3. **构建镜像和启动容器**
98+
99+
```
100+
docker-compose -f local.yml build
101+
docker-compose -f local.yml up
102+
```
103+
104+
4. **创建后台管理员账户**
105+
106+
```
107+
docker exec -it hellodjango_blog_tutorial_local python manage.py createsuperuser
108+
```
109+
110+
其中 hellodjango_blog_tutorial_local 为项目预定义容器名
111+
112+
5. 进入后台发布文章
113+
114+
在浏览器访问:http://127.0.0.1:8000/admin
115+
116+
使用第 3 步创建的后台管理员账户登录
117+
118+
具体请参阅 [创作后台开启,请开始你的表演](https://www.zmrenwu.com/courses/hellodjango-blog-tutorial/materials/65/)
90119

91120
## 教程目录索引
92121

@@ -110,6 +139,7 @@ tutorial 分支为项目的主分支,每一篇教程的代码都和历史提
110139
16. [Nginx+Gunicorn+Supervisor 部署 Django 博客应用](https://www.zmrenwu.com/courses/hellodjango-blog-tutorial/materials/74/)
111140
17. [使用 Fabric 自动化部署](https://www.zmrenwu.com/courses/hellodjango-blog-tutorial/materials/75/)
112141
18. [使用 Certbot 向 Let's Encrypt 免费申请 HTTPS 证书](https://www.zmrenwu.com/courses/hellodjango-blog-tutorial/materials/76/)
142+
19. [使用 Docker 让部署 Django 项目更加轻松](https://www.zmrenwu.com/courses/hellodjango-blog-tutorial/materials/77/)
113143

114144
## 公众号
115145
<p align="center">

blogproject/settings/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
DATABASES = {
7171
'default': {
7272
'ENGINE': 'django.db.backends.sqlite3',
73-
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
73+
'NAME': os.path.join(BASE_DIR, 'database', 'db.sqlite3'),
7474
}
7575
}
7676

compose/local/Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM python:3.6-alpine
2+
3+
ENV PYTHONUNBUFFERED 1
4+
5+
# 替换为国内源
6+
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
7+
8+
RUN apk update \
9+
# Pillow dependencies
10+
&& apk add jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev
11+
12+
WORKDIR /app
13+
14+
RUN pip install pipenv -i https://pypi.douban.com/simple
15+
16+
COPY Pipfile /app/Pipfile
17+
COPY Pipfile.lock /app/Pipfile.lock
18+
RUN pipenv install --system --deploy --ignore-pipfile
19+
20+
COPY ./compose/local/start.sh /start.sh
21+
RUN sed -i 's/\r//' /start.sh
22+
RUN chmod +x /start.sh

0 commit comments

Comments
 (0)