docker安装wagtail核心配置文件

本文最后更新于 2024年5月16日。

docker安装wagtail核心配置文件

yml文件

version: '3.7'
services:
  wagtail:
    container_name: wagtail
    # restart: unless-stopped
    image: wagtail:selfV1
    build:
      context: .
      dockerfile: Dockerfile  
    # stdin_open: true
    # tty: true
    volumes:
      - wagtailpython:/usr/local/lib/python3.11
      - wagtailapp:/app
    # ports:
    #   - "5212:8000"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.wagtail.entrypoints=websecure"
      - "traefik.http.routers.wagtail.rule=Host(`wagtail.weiyoun.com`)"
      - "traefik.http.routers.wagtail.tls.certresolver=lets-encr"
      - traefik.http.routers.wagtail.service=wagtail #多路由必须定义不同的服务名
      - "traefik.http.services.wagtail.loadbalancer.server.port=8000"
networks:
  default:
    external:
      name: traefik
volumes:
  wagtailpython:
  wagtailapp:

dockerfile


FROM python:3.11-alpine3.17
LABEL maintainer="weiyoun.com"
# 为了及时输出日志
# 221205报错Watching for file changes with StatReloader
# ENV PYTHONUNBUFFERED 0
ENV PYTHONUNBUFFERED 1
# 保持运行,在docker-compose中添加也可以,放在具体服务的子集中。不添加会因为没有任务而退出容器
ENV stdin_open true
ENV tty true
# pip安装列表,里面写需要pip安装的包
ADD requirements.txt ./
# 安装,构建网站,设置超级用户
RUN pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple \
    && wagtail start app \
    && cd app \
    && python manage.py migrate \
    && echo "from django.contrib.auth.models import User; User.objects.create_superuser('myadmin', 'myemail@example.com', 'wagtailadmin')" | python manage.py shell
# 运行网站不能写入RUN,否则不能成功构建镜像  
    # && python manage.py runserver 0.0.0.0:8000
EXPOSE 8000
VOLUME /app   /usr/local/lib/python3.11
# VOLUME ["/app"]
# VOLUME ["/usr/local/lib/python3.11"]
# VOLUME ["/app","/usr/local/lib/python3.11"]
# VOLUME [/usr/local/lib/python3.11]
# ADD . ./
CMD cd /app \
    && python manage.py runserver 0.0.0.0:8000
# sh: manage.py,: unknown operand
# CMD cd /app \
#     && [ "python", "manage.py", "runserver", "0.0.0.0:8000" ]
# 报错python: can't open file '//manage.py': [Errno 2] No such file or directory
# CMD [ "python", "manage.py", "runserver", "0.0.0.0:8000" ]
# 下面命令导致进入/app/app,wagtail exited with code 0
# CMD cd app \
#     && [ "python manage.py runserver 0.0.0.0:8000" ]
# 会在根目录执行,找不到命令
# CMD [ "python manage.py runserver 0.0.0.0:8000" ]
# 报错python: can't open file '//manage.py': [Errno 2] No such file or directory
# CMD python manage.py runserver 0.0.0.0:8000
# 下面的形式无法正常运行,把"manage.py runserver 0.0.0.0:8000"当成了一个参数,提示没有文件
# CMD [ "python", "manage.py runserver 0.0.0.0:8000" ]