在 Docker 中重新加载 discord python 机器人

Hotreloading discord python bot in Docker

我想 docker使用 python 编写的 discord 机器人进行开发,但我无法完成。 docker-compose 现在是这样的:

discord_bot:
  build: ./discord
  volumes:
    - ./discord:/usr/src/discord
  depends_on:
    - mongo
    - node

有没有办法在我仍然使用 discord.py 的同时热重载此代码?

如果您希望它在本地开发的代码更改时自动重新加载,您所拥有的大部分都是正确的。你缺少的一件事是通过某种文件观察器启动主进程。您可以使用 nodemon with python,或者专门为 python 找一些等价物。

您需要进行的更改:

  1. 您的构建映像需要包含某种文件监视器。您可以为此使用 Nodemon(甚至 python ,或使用一些 python 等价物)
  2. 您应该覆盖图像的默认命令以通过文件观察器启动。

    discord_bot:
      build: ./discord     <--- Should include file watcher executable (nodemon or some python equivalent)
      command: nodemon /usr/src/discord/index.js  <--- add this line
      volumes:
        - ./discord:/usr/src/discord
      depends_on:
        - mongo
        - node