【问题标题】:Can't Curl docker container running apache from outside the container无法从容器外部卷曲运行 apache 的 docker 容器
【发布时间】:2021-11-25 12:16:48
【问题描述】:

我无法从常规终端 curl 运行 Apache 的 php。 在容器内卷曲 localhost 会返回正确的结果。

docker-compose 文件:

version: '3'
services:
dash-api:
 build:
  context: .
  dockerfile: Dockerfile
  args:
    - GITHUB_HTTPS_TOKEN=<token>

 volumes:
   - /usr/local/:/usr/local/
   - /app:/var/www/html
 ports:
   - "80:80"

Dockerfile

FROM php:7.2.34-apache AS serve
...
EXPOSE 80
CMD ["apachectl", "-D", "FOREGROUND"]

docker 日志在请求中显示 500 错误(来自容器外)

127.0.0.1 - - [25/Nov/2021:12:05:46 +0000] "GET /gateway.php HTTP/1.1" 500 1047 "-" "curl/7.54.0"

但是卷曲一个测试文件(位于与 gateway.php 相同的文件夹中,其中包含一个 echo 会返回输出。

【问题讨论】:

  • 你能显示你正在使用的 curl 命令吗?另外,docker container ls 和/或docker ps 的输出是什么?你确定你在 CURLing 正确的 IP 吗?
  • 容器显示端口 > '0.0.0.0:80->80/tcp, :::80->80/tcp' 我正在卷曲 localhost:80
  • 如果容器访问日志显示容器收到了一个路径正确的请求,那么 Docker 网络设置是正确的。 500 错误可能是您的代码或数据库设置中的问题?

标签: php docker curl


【解决方案1】:

尝试在端口旁边添加 localhost,也许会有帮助。

version: '3'
services:
dash-api:
 build:
  context: .
  dockerfile: Dockerfile
  args:
    - GITHUB_HTTPS_TOKEN=<token>

 volumes:
   - /usr/local/:/usr/local/
   - /app:/var/www/html
 ports:
   - 127.0.0.1:80:80

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-16
    • 2017-04-15
    • 2017-01-18
    • 2019-09-03
    • 1970-01-01
    相关资源
    最近更新 更多