首页 > 解决方案 > 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"

提前感谢您的帮助!

标签: python-3.xdockerpostdocker-compose

解决方案


环境变量应该是一个列表

environment:
  - GOOGLE_APPLICATION_CREDENTIALS=${GOOGLE_APPLICATION_CREDENTIALS} 
  - DIALOGFLOW_PROJECT_ID=${DIALOGFLOW_PROJECT_ID}

此外,我在您的 docker-compose 文件中看不到环境文件。有关详细信息,请参阅此URL


推荐阅读