安装
- Debian 安装
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16~$ sudo apt-get remove docker docker-engine docker.io containerd runc
~$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
~$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
~$ echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
~$ sudo apt-get update
~$ sudo apt-get install docker-ce docker-ce-cli containerd.io
Docker
容器基本操作
1 | ~$ docker ps |
- 查看它的运行状态
1 | ~$ docker stats |
容器网络
查看网络
1
2
3
4
5~$ docker network ls
NETWORK ID NAME DRIVER SCOPE
108d6f126660 bridge bridge local
1f2d1f3f0ebf host host local
b17831300bb4 none null local查看详情
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58docker network inspect bridge
[
{
"Name": "bridge",
"Id": "108d6f126660ffa74a81eebdb65ebf5e982cfcc0a0e982cdf832de602e462dca",
"Created": "2020-11-18T09:42:07.001834136Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": true,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.17.0.0/16",
"Gateway": "172.17.0.1"
},
{
"Subnet": "2600:3c03:xx:x/64",
"Gateway": "2600:3c03:xx:x1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"3ca33d64a42243f5ac77dcf61eeb8262ff8f6a30e341b34a4f5352adc5f98ca9": {
"Name": "ss-server",
"EndpointID": "9230ae11d665b088d23ef939ee959a9ad512a2f3667106688f38e63f85f603a1",
"MacAddress": "02:42:ac:11:00:02",
"IPv4Address": "172.17.0.2/16",
"IPv6Address": "2600:3c03::242:xx:x/64"
},
"893078d9926bd8f41d669975c48be945472feaad5daed23c937ce8ab517b5a18": {
"Name": "trojan",
"EndpointID": "0c3650579b8029b9ce940459a7ac795828cb76eaec331ac179ea9708adaba8ae",
"MacAddress": "02:42:ac:11:00:03",
"IPv4Address": "172.17.0.3/16",
"IPv6Address": "2600:3c03::242:xx:x/64"
}
},
"Options": {
"com.docker.network.bridge.default_bridge": "true",
"com.docker.network.bridge.enable_icc": "true",
"com.docker.network.bridge.enable_ip_masquerade": "true",
"com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
"com.docker.network.bridge.name": "docker0",
"com.docker.network.driver.mtu": "1500"
},
"Labels": {}
}
]创建网络
1 | ~$ docker network create --ipv6 --driver=bridge --subnet=172.20.0.0/24 --subnet=2600:3c03:1111::/64 --gateway=172.20.0.1 ipv6_bridge |
- 把现有的容器连接到新的网络
1 | ~$ docker network connect ipv6_bridge <container> |
代理
在某些应用中,有时
docker
容器需要通过proxy
连接某些服服.
1 | ~$ sudo mkdir -p /etc/systemd/system/docker.service.d |
使用HTTP与Docker交互
1 | ~$ curl --unix-socket /var/run/docker.sock -H "Content-Type: application/json" \ |
配置存储驱动
- Manage data in Docker
Docker
支持多种存储驱动,默认是使用devicemapper
的loopback-lvm
方式,它是零配置,但是性能差,不推荐在生产环境中使用.生产中建议使用direct-lvm
的方式.默认的存储会有以下的警告:
1 | docker info |
- 如果磁盘镜像文件太多了,如有如下错误:
1
2docker: Error response from daemon: devmapper: Thin Pool has 486 free data blocks which is less than minimum required 163840 free data blocks. Create more free space in thin pool or use dm.min_free_space option to change behavior.
See 'docker run --help'. - 可以使用下面命令清除
docker
内的临时文件1
~$ docker system prune
Overlay2
驱动
1 | ~$ sudo mkfs.xfs -n ftype=1 /dev/sdb1 |
配置
daemon.json
,参考daemon-configuration-file1
2~$ sudo systemctl stop docker
~$ echo '{ "storage-driver": "overlay2" }' | jq '.' | sudo tee /etc/docker/daemon.json重启
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24~$ sudo systemctl start docker
~$ docker info
Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 20.10.5
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
[...]Export/Import
容器这里是在原来的
devicemapper
驱动里的容器导出,再切换到overlay2
驱动导入.1
2
3
4
5
6
7
8
9
10
11~$ docker save sickcodes/docker-osx > ~/3TB-DISK/docker-osx.tar
~$ docker load < ~/3TB-DISK/docker-osx.tar
e4f1ca1ca7a8: Loading layer [==================================================>] 731.1MB/731.1MB
ee2075d8bcfb: Loading layer [==================================================>] 35.84kB/35.84kB
a98393dc6c96: Loading layer [==================================================>] 59.95MB/59.95MB
116b71590f7b: Loading layer [==================================================>] 166MB/166MB
d3c6d5a7aa4e: Loading layer [==================================================>] 59.95MB/59.95MB
6dd5cd2c75b5: Loading layer [==================================================>] 2.048kB/2.048kB
908b86edf5d9: Loading layer [==================================================>] 2.56kB/2.56kB
c706cc5ac18e: Loading layer [==================================================>] 6.144kB/6.144kB
[...]
1 | ~$ for item in 6ffe5fbf69b7 92527f264cc9 a15038d35f57 d10b5c313d05; do |
使用multi-stage
功能
1 | FROM golang:1.16 AS builder |
- 上面这个脚本,演示如何在一个
Dockerfile
里实现分阶段创建镜像,最终的Docker镜像
体积非常小,因为它是从scratch
上构建的。
搭建基于Dokku
的PaaS
平台
- Github dokku
- Doc Dokuu
- 部署 使用 dokku 部署你的 Rails 应用
- 下面通参考Debian Package Installation Notes改编成
Playbook
文件.因为Dokku
是要与Docker
搭配使的.上面部分安装了docker
环境.所以在下面省去了.
服务端安装
1 | # 参考位置 http://dokku.viewdocs.io/dokku/getting-started/install/debian/ 改编的文件 |
- 安装完成后会启动一个
http-server
提供web
方式的配置,浏览器输入服务器ip
打开页面,输入公钥和域名(或者公网 IP)就 OK.
客户端安装
- dokku-client这个客户端很久没有更新的了,不支持 python3.
- 官方客户端,这里基于不同语言有比较全面的客户端介绍.
- Deploying Django on Dokku
- 这里使用官方的提供的客户端脚本,如下面所示,运行脚本前,先要确定几个重点,一是添加
DOKKU_HOST
环境变里,或者直接写入$HOME/.dokku/contrib/dokku_client.sh
这个脚本里面.二是能使用公钥登录目标dokku
服务器. - 在
dokku
服务器端加入一个可信的客户端公钥,操作如下:
1 | # 列出本机加入的可信公钥 |
- 下载客户端仓库.
1
2
3
4
5
6
7
8
9~$ git clone git@github.com:dokku/dokku.git ~/.dokku
# optional: make sure that the dokku_client.sh version matches your Dokku version
~$ cd ~/.dokku
~$ git checkout <tag/branch>
# add the following to either your
# .bashrc, .bash_profile, or .profile file
~$ alias dokku='$HOME/.dokku/contrib/dokku_client.sh' - 正常的客户端运行如下,与
heroku
的客户端命令极其相似.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64~$ dokku
Usage: dokku [--quiet|--trace|--rm-container|--rm|--force] COMMAND <app> [command-specific-options]
Primary help options, type "dokku COMMAND:help" for more details, or dokku help --all to see all commands.
Commands:
apps Manage Dokku apps
certs Manage Dokku apps SSL (TLS) certs
checks Manage zero-downtime settings
config Manages global and app-specific config vars
docker-options Pass options to Docker the various stages of an app
domains Manage vhost domains used by the Dokku proxy
enter Connect to a specific app container
events Show the last events (-t follows)
git Manages the git integration for an app
help Print the list of commands
logs Output app logs
network Manages network settings for an app
nginx Interact with Dokku\'s Nginx proxy
proxy Manage the proxy used by dokku on a per app
ps List processes running in app container(s)
repo Runs commands that interact with the app\'s repo
run Run a command in a new container using the current application image
scheduler-docker-local Manages the scheduler-docker-local integration for an app
shell Spawn dokku shell
ssh-keys Manage public ssh keys that are allowed to connect to Dokku
storage Mount local volume / directories inside containers
tags List all app image tags
tar Deploy applications via tarball instead of git
trace Enable dokku tracing
url Show the first URL for an application (compatibility)
urls Show all URLs for an application
version Print dokku\'s version
~$ dokku plugin:list
! Deprecated: Please use plugin:list
plugn: 0.3.0
00_dokku-standard 0.14.1 enabled dokku core standard plugin
20_events 0.14.1 enabled dokku core events logging plugin
app-json 0.14.1 enabled dokku core app-json plugin
apps 0.14.1 enabled dokku core apps plugin
build-env 0.14.1 enabled dokku core build-env plugin
certs 0.14.1 enabled dokku core certificate management plugin
checks 0.14.1 enabled dokku core checks plugin
common 0.14.1 enabled dokku core common plugin
config 0.14.1 enabled dokku core config plugin
docker-options 0.14.1 enabled dokku core docker-options plugin
domains 0.14.1 enabled dokku core domains plugin
enter 0.14.1 enabled dokku core enter plugin
git 0.14.1 enabled dokku core git plugin
logs 0.14.1 enabled dokku core logs plugin
network 0.14.1 enabled dokku core network plugin
nginx-vhosts 0.14.1 enabled dokku core nginx-vhosts plugin
plugin 0.14.1 enabled dokku core plugin plugin
proxy 0.14.1 enabled dokku core proxy plugin
ps 0.14.1 enabled dokku core ps plugin
repo 0.14.1 enabled dokku core repo plugin
scheduler-docker-local 0.14.1 enabled dokku core scheduler-docker-local plugin
shell 0.14.1 enabled dokku core shell plugin
ssh-keys 0.14.1 enabled dokku core ssh-keys plugin
storage 0.14.1 enabled dokku core storage plugin
tags 0.14.1 enabled dokku core tags plugin
tar 0.14.1 enabled dokku core tar plugin
部署Django
工程实例
- 链接:
- 下面的环境基于
Pyenv+Pipenv
.Pyenv:python
版本管理器.Pipenv:python
包管理器,更好用的pip
. - pyenv的一些基本操作.
pyenv
安装的位置1
2~$ which pyenv
/home/lcy/.pyenv/bin/pyenvpyenv
可提供的安装版本.1
2
3
4
5
6
7
8
9
10
11~$ pyenv install --list
Available versions:
2.1.3
2.2.3
2.3.7
2.4
2.4.1
2.4.2
2.4.3
2.4.4
[...]- 本机已经安装的版本
1
2
3
4
5
6
7~$ pyenv versions
system
* 3.6.6 (set by /home/lcy/.python-version)
3.6.6/envs/dokku-py3
3.6.6/envs/py3dev
dokku-py3
py3dev - 本机默认使用的版本.
1
2~$ pyenv version
3.6.6 (set by /home/lcy/.python-version) - 为这当前版
pyenv
本安装pipenv1
2~$ pip install pipenv
Collecting pipenv - 列出当前安装的包.
1
2
3
4
5
6
7
8
9
10
11
12~$ pip list
Package Version
---------------- ----------
autopep8 1.4
certifi 2018.11.29
pip 18.1
pipenv 2018.11.26
pycodestyle 2.4.0
setuptools 39.0.1
virtualenv 16.2.0
virtualenv-clone 0.4.0
yapf 0.23.0
- 通过上述命令安装了pipenv,下面是它的一些基本操作.官方文档
- 下面是创建
python3
的虚拟环境,也可以用pipenv --python 3.7
指定具体的版本号.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20~$ pipenv --three
Creating a virtualenv for this project…
Pipfile: /home/lcy/workspace/dokku-test/crm/Pipfile
Using /home/lcy/.pyenv/versions/3.6.6/bin/python3.6 (3.6.6) to create virtualenv…
⠸ Creating virtual environment...Already using interpreter /home/lcy/.pyenv/versions/3.6.6/bin/python3.6
Using base prefix '/home/lcy/.pyenv/versions/3.6.6'
New python executable in /home/lcy/.local/share/virtualenvs/crm-GMqHkluo/bin/python3.6
Also creating executable in /home/lcy/.local/share/virtualenvs/crm-GMqHkluo/bin/python
Installing setuptools, pip, wheel...
done.
✔ Successfully created virtual environment!
Virtualenv location: /home/lcy/.local/share/virtualenvs/crm-GMqHkluo
Creating a Pipfile for this project…
# 查看环境位置.
~$ pipenv --venv
/home/lcy/.local/share/virtualenvs/crm-GMqHkluo
~$ pipenv --py
/home/lcy/.local/share/virtualenvs/crm-GMqHkluo/bin/python
- 安装
django
依赖包.当前工程目录下的Pipfile.lock
文件,就等同于传统的requirements.txt
文件.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16~$ pipenv install django django-toolbelt
Installing django…
Adding django to Pipfile\'s [packages]…
✔ Installation Succeeded
Installing django-toolbelt…
Adding django-toolbelt to Pipfile\'s [packages]…
✔ Installation Succeeded
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
✔ Success!
Updated Pipfile.lock (c14d8c)!
Installing dependencies from Pipfile.lock (c14d8c)…
🐍 ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 8/8 — 00:00:01
To activate this project\'s virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run. - 列出安装包的的依赖.
1
2
3
4
5
6
7
8
9~$ pipenv graph
django-toolbelt==0.0.1
- dj-database-url [required: Any, installed: 0.5.0]
- dj-static [required: Any, installed: 0.0.6]
- static3 [required: Any, installed: 0.7.0]
- django [required: Any, installed: 2.1.5]
- pytz [required: Any, installed: 2018.9]
- gunicorn [required: Any, installed: 19.9.0]
- psycopg2 [required: Any, installed: 2.7.6.1] - 进入
pipenv
虚拟环境shell
1
2
3~$ pipenv shell
Launching subshell in virtual environment…
. /home/lcy/.local/share/virtualenvs/cms-uhqZcysp/bin/activate
创建Django
的示例项目.
1 | ~$ mkdir dokkutest && cd dokkutest |
Dokku
其它指南
设置
APP
域名.如上面所述,app
映射了一个很大端口值http://172.16.10.100:51903
,只能通过IP+端口的方式访问,这有可能不能满足我们的实际应用需求,怎样在同一个IP
里使用不同的域名访问不同的应用呢?或者说,同一个服务器里的应用都想通过80端口对外提供服务.这里就要通过nginx
代理不同的域名.命令如下:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17~$ dokku domains:help
Usage: dokku domains[:COMMAND]
Manage vhost domains used by the Dokku proxy.
Additional commands:
domains:add <app> <domain> [<domain> ...] Add domains to app
domains:add-global <domain> [<domain> ...] Add global domain names
domains [<app>] [DEPRECATED] Alternative for domains:report
domains:clear <app> Clear all domains for app
domains:disable <app> Disable VHOST support
domains:enable <app> Enable VHOST support
domains:remove <app> <domain> [<domain> ...] Remove domains from app
domains:remove-global <domain> [<domain> ...] Remove global domain names
domains:report [<app>] [<flag>] Displays a domains report for one or more apps
domains:set <app> <domain> [<domain> ...] Set domains for app
domains:set-global <domain> [<domain> ...] Set global domain names为
dokkutest
这个应用设置test.example.com
这个域名,后面就可以通过个域名 80 端就能访问到这个应用了.
1 | ~$ dokku domains:test.example.com dokkutest |
- 访问静态资源.其实上面的部署是一个基本的应用,做一个
Restful API
服务器是没有问题的.如果做成网页端,它的static
下的静态资源是不能访问的.这里要用到一些其它包与设置.具体参照这里 Django and Static Assets.具体解决如下:
1 | # 安装whitenoise |
Dokku
插件应用
letsencrypt
1 | # 安装 |
- 为
APP
安装Lets'Encrypt
,这里需要注意,这个app
设置了三个域名,其中只有一个是在DNS
上设置的h5.lcy.wiki
,所以才会出现下面的错误.只要把其它两个域名从这个app
中删除就可以了.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30~$ dokku letsencrypt h5dev
=====> Let\'s Encrypt h5dev
-----> Updating letsencrypt docker image...
[...]
-----> Enabling ACME proxy for h5dev...
-----> Getting letsencrypt certificate for h5dev...
- Domain 'h5dev.www.lcy.wiki'
- Domain 'h5.lcy.wiki'
- Domain 'h5dev'
[...]
ACME server returned an error: urn:acme:error:malformed :: The request message was malformed :: Error creating new authz :: DNS name does not have enough labels
Debugging tips: -v improves output verbosity. Help is available under --help.
-----> Certificate retrieval failed!
-----> Disabling ACME proxy for h5dev...
done
# 正常应该如下所示
~$ dokku domains:report h5dev
=====> h5dev domains information
Domains app enabled: true
Domains app vhosts: h5.lcy.wiki
~$ dokku letsencrypt:ls
-----> App name Certificate Expiry Time before expiry Time before renewal
h5dev 2019-06-18 18:42:21 89d, 20h, 14m, 52s 59d, 20h, 14m, 52s
# 自动刷新证书
~$ dokku letsencrypt:auto-renew h5dev
h5dev still has 59d, 20h, 12m, 43s days left before renewal
- 错误
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19dokku letsencrypt yfh5
=====> Let's Encrypt yfh5
-----> Updating letsencrypt docker image...
0.1.0: Pulling from dokku/letsencrypt
Digest: sha256:af5f8529c407645e97821ad28eba328f4c59b83b2141334f899xxxxxxxxxx
Status: Image is up to date for dokku/letsencrypt:0.1.0
docker.io/dokku/letsencrypt:0.1.0
Done updating
-----> Enabling ACME proxy for yfh5...
-----> Getting letsencrypt certificate for yfh5...
/var/lib/dokku/plugins/available/letsencrypt/functions: line 145: get_app_domains: command not found
^[[1;3Rdarkhttpd/1.12, copyright (c) 2003-2016 Emil Mikulic.
listening on: http://0.0.0.0:80/
You must set at least one -d/--vhost
Debugging tips: -v improves output verbosity. Help is available under --help.
-----> Certificate retrieval failed!
-----> Disabling ACME proxy for yfh5...
done
redis
插件应用
- dokku-redis
- How to connect to redis with dokku and flask?
- 安装插件,并创建数据库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15~$ sudo dokku plugin:install https://github.com/dokku/dokku-redis.git redis
~$ dokku redis:create dokku-redis
~$ dokku redis:info dokku-redis
=====> Container Information
# 这两行是映射到宿主机的实际目录下面.
Config dir: /var/lib/dokku/services/redis/dokku-redis/config
Data dir: /var/lib/dokku/services/redis/dokku-redis/data
Dsn: redis://dokku-redis:df40bbae8555a06d52f937fd4072ad98ec6e58563f84686254b43ff946605e4c@dokku-redis-dokku-redis:6379
Exposed ports: -
Id: e535a815b6bdc6898c9e6615d2e3fe0dd7387598bc6795aaf0529ad998b2f114
Internal ip: 172.17.0.8
Links:
Service root: /var/lib/dokku/services/redis/dokku-redis
Status: running
Version: redis:4.0.11 - 连接
redis
与容器应用服务1
2
3
4
5
6
7
8
9
10
11
12
13~$ dokku redis:link dokku-redis yfh5
-----> Setting config vars
REDIS_URL: redis://dokku-redis:df40bbae8555a06d52f937fd4072ad98ec6e58563f84686254b43ff946605e4c@dokku-redis-dokku-redis:6379
-----> Restarting app yfh5
-----> Releasing yfh5 (dokku/yfh5:latest)...
[...]
~$ dokku redis:info dokku-redis
[...]
Internal ip: 172.17.0.8
Links: yfh5
Service root: /var/lib/dokku/services/redis/dokku-redis
[...] - 添加到
Django
项目中用作 Sessiong Cache ,修改settings.py
的内容如下:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17CACHES = {
"default": {
"BACKEND":
"django_redis.cache.RedisCache",
"LOCATION":
"redis://dokku-redis:df40bbae8555a06d52f937fd4072ad98ec6e58563f84686254b43ff946605e4c@dokku-redis-dokku-redis:6379",
"OPTIONS": {
"DB":
0,
"PASSWORD":
"df40bbae8555a06d52f937fd4072ad98ec6e58563f84686254b43ff946605e4c",
"CONNECTION_POOL_KWARGS": {
"max_connections": 65535
},
}
}
}
设置Settings.py
- 链接:
- 因为
Django
开发测试需要与数据库连接,且开发环境与生产(测试)部署的环境是不一样的,这里可以通过在settings.py
判断系统环境变量来做出一些自动化.上面那个链很有参考意.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56# We should get this from the environment, never store them in git.
# 为了安全建义不要SECRET_KEY直接写入settings.py,它会保存在git上面记录.可以使用 dokku config:set appname SECRET_KEY='xxxxxx'
SECRET_KEY = os.environ.get("SECRET_KEY", 'secret')
# Set DEBUG to False if the NODEBUG env var has been set.
DEBUG = True if os.environ.get("NODEBUG") is None else False
# Set the allowed hosts based on the environment.
ALLOWED_HOSTS = ["web", "localhost"] if os.environ.get("NODEBUG") is None else [".yourdomain.com"]
if os.environ.get("IN_DOCKER"):
# Stuff for when running in Docker-compose.
# 使用Docker-compose会有IN_DOCKER这个环境变量
CELERY_BROKER_URL = 'redis://redis:6379/1'
CELERY_RESULT_BACKEND = 'redis://redis:6379/1'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': "postgres",
'USER': 'postgres',
'PASSWORD': 'password',
'HOST': "db",
'PORT': 5432,
}
}
elif os.environ.get("DATABASE_URL"):
# Stuff for when running in Dokku.
# Parse the DATABASE_URL env var.
USER, PASSWORD, HOST, PORT, NAME = re.match("^postgres://(?P<username>.*?)\:(?P<password>.*?)\@(?P<host>.*?)\:(?P<port>\d+)\/(?P<db>.*?)$", os.environ.get("DATABASE_URL", "")).groups()
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': NAME,
'USER': USER,
'PASSWORD': PASSWORD,
'HOST': HOST,
'PORT': int(PORT),
}
}
CELERY_BROKER_URL = os.environ.get("REDIS_URL", "") + "/1"
CELERY_RESULT_BACKEND = os.environ.get("REDIS_URL", "") + "/1"
else:
# Stuff for when running locally.
CELERY_TASK_ALWAYS_EAGER = True
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
Mysql
插件应用
1 | ~$ sudo dokku plugin:install https://github.com/dokku/dokku-mysql.git mysql |
Persistent Storage
- 参考链接
- 这里需要在主机上先建一个目录,供给容器内挂载,官方推荐是
/var/lib/dokku/data/storage
,这里可以是其它文件系统目录,- 如:
cephfs,nfs
等.关于volume
与主机共享数据使用,也可以参考http://dokku.viewdocs.io/dokku/advanced-usage/docker-options/
. - 如:
dokku docker-options:add node-js-app deploy,run "-v /var/log/node-js-app:/app/logs"
1
2~$ sudo dokku plugin:install storage
~$ dokku storage:mount node-js-app /var/lib/dokku/data/storage/node-js-app:/storage
- 如:
- 为了配合
Linux
的权限,需要把storage
下的node-js-app
目录设置成chown -R 32767:dokku node-js-app
权限.
常见的错误
1 | ~$ -----> Python app detected |
- 如果出现上述错误,请重新提交.
与 WebPack 集成
- django-webpack-loader
- 用 django-webpack-loader 实现 Django 和 Webpack 的绑定
- package.json 文件
- vue+django+webpack 搭建
- Angular 6|5 Tutorial: Integrating Angular with Django
谢谢支持
- 微信二维码: