python-3.x - POST 请求在 docker-compose 容器中不起作用
问题描述
我在向使用 docker-compose 方法构建的 docker 容器发送发布请求时遇到问题。当我发送发布请求时,我收到 405 错误->“消息”:“请求的 URL 不允许该方法。”。重要的是,当我将同一个容器与 docker run 命令一起使用时,post 请求会起作用。我猜问题可能是 docker-compose.yml 文件。
Dockerfile
FROM python:3.6-alpine
EXPOSE 5005
WORKDIR /dialogflow_nlp_connector
COPY requirements.txt /dialogflow_nlp_connector
RUN apk add --no-cache --virtual .build-deps g++ musl-dev
RUN pip install -r requirements.txt
COPY . /dialogflow_nlp_connector/
CMD ["python", "run.py"]
Docker-Compose.yml
version: "3"
services:
intent-handler:
build: ./intent_handling
volumes:
- ./intent_handling:/dialogflow_nlp_connector
environment:
GOOGLE_APPLICATION_CREDENTIALS: ${GOOGLE_APPLICATION_CREDENTIALS}
DIALOGFLOW_PROJECT_ID: ${DIALOGFLOW_PROJECT_ID}
ports:
- "5005:5005"
slack_event_handler:
build: ./slack_events_api
volumes:
- ./slack_events_api:/slack_event_handler
environment:
SLACK_BOT_TOKEN: ${SLACK_BOT_TOKEN}
SLACK_SIGNING_TOKEN: ${SLACK_SIGNING_TOKEN}
SLACK_VERIFICATION_TOKEN: ${SLACK_VERIFICATION_TOKEN}
FALLBACK_MESSAGE: "Sorry something went wrong :c Please try again in a moment!"
ports:
- "3000:3000"
提前感谢您的帮助!
解决方案
环境变量应该是一个列表
environment:
- GOOGLE_APPLICATION_CREDENTIALS=${GOOGLE_APPLICATION_CREDENTIALS}
- DIALOGFLOW_PROJECT_ID=${DIALOGFLOW_PROJECT_ID}
此外,我在您的 docker-compose 文件中看不到环境文件。有关详细信息,请参阅此URL。
推荐阅读
- docker - 为什么我在 docker 网络示例中看到 172.22.0.3?
- django - Django 从 ManyToManyField 表单中获取对象的数据
- java - 为什么有些行用绿色矩形突出显示以及如何在 intellij IDEA 中将其关闭
- java - Java ObjectInpuStream 读取 DefaultTableModel
- python - 为什么我得到“str”对象不可调用错误
- methods - 无论如何,“context”和“with_context”有什么区别?
- go - 为什么 float 32 和 float64 在 go 中打印为整数?
- python - 在 Python 中使用 Selenium 禁用 Chrome“此浏览器正在由自动测试软件控制”时出现问题
- c# - 将参数从 Razor 页面传递给 Razor 组件
- ios - tableViewCell 没有更新数据,而是将新获取的数据附加到前一个数据中