docker安装wagtail探索过程

本文最后更新于 2023年10月26日。

221205构建成功

[docker安装wagtail核心配置文件]

进入容器报错

[root@iZ8vbajg9wo8iwynfb1lgeZ dc_wagtail]# docker exec -it wagtail bash
OCI runtime exec failed: exec failed: unable to start container process: exec: "bash": executable file not found in $PATH: unknown

由于使用的是python镜像为基础镜像,使用的是精简系统alphine,没有安装bash,只有sh,所以进入容器无法使用bash命令。
需要用python

docker exec -it wagtail python

或者使用

docker exec -it wagtail /bin/sh

查找python位置

/ # find . -name 'python'
./usr/local/bin/python
/ # find . -name 'wagtail'
./usr/local/bin/wagtail
./usr/local/lib/python3.11/site-packages/wagtail
/ #
/ # wagtail start app
Creating a Wagtail project called app
Success! app has been created
/ # cd app
/app # python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, home, sessions, taggit, wagtailadmin, wagtailcore, wagtaildocs, wagtailembeds, wagtailforms, wagtailimages, wagtailredirects, wagtailsearch, wagtailusers
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK

非交互创建用户

/app # echo "from django.contrib.auth.models import User; User.objects.create_superuser('myadmin', 'myemail@example.com', 'hunter2')" | python manage.py shell
/app #

在docker中直接搭建时采用如下用户名

# echo "from django.contrib.auth.models import User; User.objects.create_superuser('myadmin', 'myemail@example.com', 'wagtailadmin')" | python manage.py shell

容器内部运行服务日志,不推荐这个开启方法

/app # echo "from django.contrib.auth.models import User; User.objects.create_superuser('myadmin', 'myemail@example.com', 'hunter2')" | python manage.py shell
/app # python manage.py runserverpython manage.py runserver
Unknown command: 'runserverpython'. Did you mean runserver?
Type 'manage.py help' for usage.
/app # python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
December 05, 2022 - 06:21:25
Django version 4.1.3, using settings 'app.settings.dev'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
/app # python manage.py runserver 127.0.0.1:80
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
December 05, 2022 - 06:24:19
Django version 4.1.3, using settings 'app.settings.dev'
Starting development server at http://127.0.0.1:80/
Quit the server with CONTROL-C.

docker中直接运行wagtail会无法访问

/app/app # python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
December 05, 2022 - 07:11:47
Django version 4.1.3, using settings 'app.settings.dev'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

需要指定地址0.0.0.0才行

/app/app # python manage.py runserver 0.0.0.0:8000
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
December 05, 2022 - 07:25:03
Django version 4.1.3, using settings 'app.settings.dev'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
[05/Dec/2022 07:25:11] "GET / HTTP/1.1" 200 6830
[05/Dec/2022 07:25:11] "GET /static/css/app.css HTTP/1.1" 200 0
[05/Dec/2022 07:25:11] "GET /static/css/welcome_page.css HTTP/1.1" 200 2522
[05/Dec/2022 07:25:11] "GET /static/js/app.js HTTP/1.1" 200 0
Not Found: /favicon.ico
[05/Dec/2022 07:25:11] "GET /favicon.ico HTTP/1.1" 404 3365