Docker&Celery - 错误:Pidfile (celerybeat.pid) 已存在

2024-04-08

应用程序包括: - 姜戈 - 雷迪斯 - 芹菜 - 码头工人 - Postgres

在将项目合并到 docker 之前,一切都运行顺利且正常,但是一旦将其移入容器,就开始出现问题。 起初它开始得很好,但过了一会儿我确实收到了以下错误:

celery-beat_1  | ERROR: Pidfile (celerybeat.pid) already exists.

我已经为此挣扎了一段时间,但现在我真的放弃了。我不知道有什么问题。

Dockerfile:

FROM python:3.7

ENV PYTHONUNBUFFERED 1
RUN mkdir -p /opt/services/djangoapp/src


COPY /scripts/startup/entrypoint.sh entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

COPY Pipfile Pipfile.lock /opt/services/djangoapp/src/
WORKDIR /opt/services/djangoapp/src
RUN pip install pipenv && pipenv install --system

COPY . /opt/services/djangoapp/src

RUN find . -type f -name "celerybeat.pid" -exec rm -f {} \;

RUN sed -i "s|django.core.urlresolvers|django.urls |g" /usr/local/lib/python3.7/site-packages/vanilla/views.py
RUN cp /usr/local/lib/python3.7/site-packages/celery/backends/async.py /usr/local/lib/python3.7/site-packages/celery/backends/asynchronous.py
RUN rm /usr/local/lib/python3.7/site-packages/celery/backends/async.py
RUN sed -i "s|async|asynchronous|g" /usr/local/lib/python3.7/site-packages/celery/backends/redis.py
RUN sed -i "s|async|asynchronous|g" /usr/local/lib/python3.7/site-packages/celery/backends/rpc.py

RUN cd app && python manage.py collectstatic --no-input



EXPOSE 8000
CMD ["gunicorn", "-c", "config/gunicorn/conf.py", "--bind", ":8000", "--chdir", "app", "example.wsgi:application", "--reload"]

docker-compose.yml:

version: '3'

services:

  djangoapp:
    build: .
    volumes:
      - .:/opt/services/djangoapp/src
      - static_volume:/opt/services/djangoapp/static  # <-- bind the static volume
      - media_volume:/opt/services/djangoapp/media  # <-- bind the media volume
      - static_local_volume:/opt/services/djangoapp/src/app/static
      - media_local_volume:/opt/services/djangoapp/src/app/media
      - .:/code
    restart: always
    networks:
      - nginx_network
      - database1_network # comment when testing
      # - test_database1_network # uncomment when testing
      - redis_network
    depends_on:
      - database1 # comment when testing
      # - test_database1 # uncomment when testing
      - migration
      - redis

  # base redis server
  redis:
    image: "redis:alpine"
    restart: always
    ports: 
      - "6379:6379"
    networks:
      - redis_network
    volumes:
      - redis_data:/data

  # celery worker
  celery:
    build: .
    command: >
      bash -c "cd app && celery -A example worker --without-gossip --without-mingle --without-heartbeat -Ofair"
    volumes:
      - .:/opt/services/djangoapp/src
      - static_volume:/opt/services/djangoapp/static  # <-- bind the static volume
      - media_volume:/opt/services/djangoapp/media  # <-- bind the media volume    
      - static_local_volume:/opt/services/djangoapp/src/app/static
      - media_local_volume:/opt/services/djangoapp/src/app/media
    networks:
      - redis_network
      - database1_network # comment when testing
      # - test_database1_network # uncomment when testing
    restart: always
    depends_on:
      - database1 # comment when testing
      # - test_database1 # uncomment when testing
      - redis
    links:
      - redis

  celery-beat:
    build: .
    command: >
      bash -c "cd app && celery -A example beat"
    volumes:
      - .:/opt/services/djangoapp/src
      - static_volume:/opt/services/djangoapp/static  # <-- bind the static volume
      - media_volume:/opt/services/djangoapp/media  # <-- bind the media volume
      - static_local_volume:/opt/services/djangoapp/src/app/static
      - media_local_volume:/opt/services/djangoapp/src/app/media
    networks:
      - redis_network
      - database1_network # comment when testing
      # - test_database1_network # uncomment when testing
    restart: always
    depends_on:
      - database1 # comment when testing
      # - test_database1 # uncomment when testing
      - redis
    links:
      - redis

  # migrations needed for proper db functioning
  migration:
    build: .
    command: >
      bash -c "cd app && python3 manage.py makemigrations && python3 manage.py migrate"
    depends_on:
      - database1 # comment when testing
      # - test_database1 # uncomment when testing
    networks:
     - database1_network # comment when testing
     # - test_database1_network # uncomment when testing

  # reverse proxy container (nginx)
  nginx:
    image: nginx:1.13
    ports:
      - 80:80
    volumes:
      - ./config/nginx/conf.d:/etc/nginx/conf.d
      - static_volume:/opt/services/djangoapp/static  # <-- bind the static volume
      - media_volume:/opt/services/djangoapp/media  # <-- bind the media volume
      - static_local_volume:/opt/services/djangoapp/src/app/static
      - media_local_volume:/opt/services/djangoapp/src/app/media 
    restart: always
    depends_on:
      - djangoapp
    networks:
      - nginx_network

  database1: # comment when testing
    image: postgres:10 # comment when testing
    env_file: # comment when testing
      - config/db/database1_env # comment when testing
    networks: # comment when testing
      - database1_network # comment when testing
    volumes: # comment when testing
      - database1_volume:/var/lib/postgresql/data # comment when testing

  # test_database1: # uncomment when testing
    # image: postgres:10 # uncomment when testing
    # env_file: # uncomment when testing
      # - config/db/test_database1_env # uncomment when testing
    # networks: # uncomment when testing
      # - test_database1_network # uncomment when testing
    # volumes: # uncomment when testing
      # - test_database1_volume:/var/lib/postgresql/data # uncomment when testing


networks:
  nginx_network:
    driver: bridge
  database1_network: # comment when testing
    driver: bridge # comment when testing
  # test_database1_network: # uncomment when testing
    # driver: bridge # uncomment when testing
  redis_network:
    driver: bridge
volumes:
  database1_volume: # comment when testing
  # test_database1_volume: # uncomment when testing
  static_volume:  # <-- declare the static volume
  media_volume:  # <-- declare the media volume
  static_local_volume:
  media_local_volume:
  redis_data:

请忽略“test_database1_volume”,因为它仅用于测试目的。


另一种解决方案(取自https://stackoverflow.com/a/17674248/39296 https://stackoverflow.com/a/17674248/39296)是使用 --pidfile= (没有路径)根本不创建 pidfile。和上面Siyu的回答效果一样。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Docker&Celery - 错误:Pidfile (celerybeat.pid) 已存在 的相关文章

随机推荐

  • 保存 Excel 文档 Apache POI

    我需要从 Excel 文档创建信息 我使用 Java 和 Apache POI 这是我的代码 Get path with JFileChooser public static String LeeRuta JFileChooser choo
  • CATransform3D 旋转导致一半图像消失

    我使用以下代码来旋转图像 但已旋转到页面 之外 的图像的一半 沿 y 轴向下 消失了 怎么修 heading以弧度为单位 CALayer layer myUIImageView layer CATransform3D rotationAnd
  • 禁用“使用 use strict 的函数形式”,但保留“缺少 'use strict' 语句”警告

    我正在使用 jslint 来验证我的代码 我的所有页面上都有 use strict 如何禁用消息 使用 use strict 的函数形式 但保留 缺少 use strict 语句 警告 这样我就不会忘记将其放在新文件中 Thanks 根据克
  • free 不会删除分配给指针(int 数组)的内存,使用 free 两次可以工作,为什么?

    这是出于好奇 我试图找到我对之前问题的疑问的答案 但他们似乎没有答案 所以在这里询问 我刚刚编写了一段代码 试图将内存分配给 int 指针 以填充数组 并扫描 int 值 一旦我完成了数组 我想删除分配给指针的数据 内存 尽管我的代码工作正
  • 错误:pandas 哈希表 keyerror

    我已经使用 pandas 成功读取了 csv 文件 当我尝试从数据框中打印特定列时 我收到关键错误 特此 我分享带有错误的代码 import pandas as pd reviews new pd read csv D aviva csv
  • 离子科尔多瓦飞溅屏幕/图标

    我正在使用适用于 iOS 和 Android 的 Ionic Framework 设计一个应用程序 我配置了启动屏幕和图标 但当我在手机上运行该应用程序时 我仍然有默认的 Cordova 启动屏幕和图标 使用ionic run androi
  • 不完整日期的策略

    正在开发一个应用程序 我们希望用户能够输入不完整的日期 在某些情况下 只有一年 例如 1854 年 或者可能有一年和一个月 例如 1983 年 3 月 或者可能有完整的日期 2001 年 6 月 11 日 我们想要一个 日期 属性 列 并且
  • 在 Windows 上使用 bcrypt 3.0.1 和 ruby​​2.0 时出现问题

    有人在 Windows 8 上安装 bcrypt 3 0 1 或 3 1 2 时遇到任何问题吗 我尝试过测试不同的版本 但出现此错误 但运行 Rails 服务器后出现此错误 无法加载此类文件 2 0 bcrypt ext 您的应用程序中没有
  • 本地#includes

    有没有某种方法可以在本地 include 标准内容 一次针对一个函数 一个类等 而不是全局的 举一个非常简单的例子 人们可能想使用 std string 但它只在一个类中需要 并且您不希望它的开销无处不在 而不是制作 include本地 您
  • componentWillReceiveProps 未触发

    在我的其他课程中 componentWillReceiveProps 工作得很好 但由于某种原因 它在这里没有触发 ItemView jsx class ItemView extends React Component constructo
  • MySQL 中多列的不同

    我希望找出 MySQL 数据库中不同行的计数 id val1 val2 val3 1 1 1 1 2 1 1 1 3 2 2 2 4 2 2 2 在上表中 查询将返回 val1 val2 val3 count 1 1 1 2 2 2 2 2
  • 如何在 case_when 语句中检测多个正则表达式

    我最近从 ifelse 转换为case when from dplyr Aim 我希望能够使用以下命令从数据帧中的语句中检测多个正则表达式case when如下 Input statement lt data frame statement
  • C++ 运算符查找规则 / Koenig 查找

    在编写测试套件时 我需要提供一个实现operator lt lt std ostream 供 Boost 单元测试使用 这有效 namespace theseus namespace core std ostream operator lt
  • 如何使用dotnetbrowser获取ajax请求响应正文?

    我已经浏览了 dotnetbrowser 网站上的文档 同时我看到了一个示例 展示了如何交叉 Ajax 调用或过滤 Ajax 调用 我想知道执行后是否可以获取 Ajax 请求正文响应 如果可能的话我该怎么做 是的 可以在 DotNetBro
  • 在 AWS lambda Node JS 的 http 响应标头中设置 Cookie

    我启用了 Lambda 代理集成 并将响应标头设置为 Lambda 输出和 API 网关的一部分 API 网关会将它们作为 HTTP 响应的一部分返回给客户端 示例代码 callback null statusCode 302 Locati
  • 如何形成独特的年、月、日的嵌套结构?

    我有一个日期数组 如下所示 2020 06 20T11 18 40 359Z 2020 06 15T11 17 45 511Z 2020 05 13T11 19 45 511Z 2019 04 20T11 49 27 828Z 我该怎么做才
  • Android Studio 3.3 xml 在 LinearLayout 上预览内部阴影

    我刚刚将 Android Studio 更新到版本 3 3 现在 在每个 XML 文件中 每个嵌套的 LinearLayout 的左侧和右侧都有一个内部阴影 如何将其去除 None
  • 如何使我的电子邮件代码适用于 PHP?

    嘿 此代码应该在未在电子邮件表单上输入输入时添加错误消息 并且应该在您最终输入代码时删除错误消息 我有两个使用以下代码 Generate a unique code function getUniqueCode length code md
  • AJAX 不更新部分视图

    我目前很难使用 Ajax 更新部分视图而无需刷新整个页面 我正在使用 MVC 和实体框架来构建视图 我将尝试尽可能多地包括在内以帮助解释自己 我有一个 div 将用于保存我所有评论的列表视图 div div 该 div 使用以下内容填充 S
  • Docker&Celery - 错误:Pidfile (celerybeat.pid) 已存在

    应用程序包括 姜戈 雷迪斯 芹菜 码头工人 Postgres 在将项目合并到 docker 之前 一切都运行顺利且正常 但是一旦将其移入容器 就开始出现问题 起初它开始得很好 但过了一会儿我确实收到了以下错误 celery beat 1 E