gpt4 book ai didi

mongodb - Docker 中的 Symfony 应用程序在 URL 调用中没有响应

转载 作者:可可西里 更新时间:2023-11-01 09:14:49 31 4
gpt4 key购买 nike

[已解决]

我想在 Docker 镜像中添加带有 MongoDB 的 Symfony 应用程序代码。

在我构建应用程序图像并接收到:

PS E:\myapi> docker-compose up
Starting mongo
Starting myapi_web_server_1
Attaching to mongo, myapi_web_server_1
mongo | 2017-04-21T13:36:23.464+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=37e6234dbaf5
mongo | 2017-04-21T13:36:23.464+0000 I CONTROL [initandlisten] db version v3.0.14
mongo | 2017-04-21T13:36:23.464+0000 I CONTROL [initandlisten] git version: 08352afcca24bfc145240a0fac9d28b978ab77f3
mongo | 2017-04-21T13:36:23.464+0000 I CONTROL [initandlisten] build info: Linux ip-10-30-223-232 3.2.0-4-amd64 #1 SMP Debian 3.2.46-1 x86_64 BOOST_LIB_VERSION=1_49
mongo | 2017-04-21T13:36:23.464+0000 I CONTROL [initandlisten] allocator: tcmalloc
mongo | 2017-04-21T13:36:23.464+0000 I CONTROL [initandlisten] options: { storage: { mmapv1: { smallFiles: true } } }
mongo | 2017-04-21T13:36:23.476+0000 I JOURNAL [initandlisten] journal dir=/data/db/journal
mongo | 2017-04-21T13:36:23.476+0000 I JOURNAL [initandlisten] recover : no journal files present, no recovery needed
mongo | 2017-04-21T13:36:23.742+0000 I JOURNAL [durability] Durability thread started
mongo | 2017-04-21T13:36:23.742+0000 I JOURNAL [journal writer] Journal writer thread started
mongo | 2017-04-21T13:36:23.871+0000 I NETWORK [initandlisten] waiting for connections on port 27017
web_server_1 | 9-1ubuntu4.21 Development Server started at Fri Apr 21 13:36:24 2017
web_server_1 | Listening on http://0.0.0.0:8000
web_server_1 | Document root is /var/www
web_server_1 | Press Ctrl-C to quit.

但是当我想访问http://172.17.0.3:8000/my_api/ ,其中 172.17.0.3 是容器的 IP,我在 Postman 中收到消息:

enter image description here

docker-compose.yml 文件

web_server:
build: web_server/
ports:
- "8000:8000"
links:
- mongo
tty: true
environment:
SYMFONY__MONGO_ADDRESS: mongo
SYMFONY__MONGO_PORT: 27017

mongo:
image: mongo:3.0
container_name: mongo
command: mongod --smallfiles
expose:
- 27017

命令 docker-compose ps 的结果

PS E:\myapi> docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------------------------------
myapi_web_server_1 /bin/bash /entrypoint.sh Up 0.0.0.0:8000->8000/tcp
mongo docker-entrypoint.sh mongo ... Up 27017/tcp

命令 docker inspect myapi_web_server_1 的结果

"NetworkSettings": {
"Bridge": "",
"SandboxID": "774a7dcbdbfbf7e437ddff340aedd4ce951dffa7a80deab9afb6e6a8abc70bde",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"8000/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "8000"
}
]
},
"SandboxKey": "/var/run/docker/netns/774a7dcbdbfb",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "4c96f6e6f8a2c80dd7ea7469dd9d74760be1af81a8039a4f835145b8f1ef5fb5",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.3",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:03",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "e174576418903bf0809edd47b77d52e2fc7644d5aacafa15ec6a8f2d15458b8a",
"EndpointID": "4c96f6e6f8a2c80dd7ea7469dd9d74760be1af81a8039a4f835145b8f1ef5fb5",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.3",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:03"
}
}
}

当我尝试从 http://127.0.0.1:8000/my_api 调用时,我收到了 Postman

enter image description here

在控制台中:

web_server_1  | [Fri Apr 21 13:51:08 2017] 172.17.0.1:33382 [404]: /my_api - No such file or directory

Dockerfile内容为

FROM ubuntu:14.04

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update && apt-get install -y \
git \
curl \
php5-cli \
php5-json \
php5-intl

RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer

ADD entrypoint.sh /entrypoint.sh
ADD ./code /var/www

WORKDIR /var/www

#RUN chmod +x /entrypoint.sh
ENTRYPOINT [ "/bin/bash", "/entrypoint.sh" ]

列出路线

PS E:\myapi\web_server\code>  php bin/console debug:router
----------------------------------- -------- -------- ------ -----------------------------------
Name Method Scheme Host Path
----------------------------------- -------- -------- ------ -----------------------------------
_wdt ANY ANY ANY /_wdt/{token}
_profiler_home ANY ANY ANY /_profiler/
_profiler_search ANY ANY ANY /_profiler/search
_profiler_search_bar ANY ANY ANY /_profiler/search_bar
_profiler_info ANY ANY ANY /_profiler/info/{about}
_profiler_phpinfo ANY ANY ANY /_profiler/phpinfo
_profiler_search_results ANY ANY ANY /_profiler/{token}/search/results
_profiler_open_file ANY ANY ANY /_profiler/open
_profiler ANY ANY ANY /_profiler/{token}
_profiler_router ANY ANY ANY /_profiler/{token}/router
_profiler_exception ANY ANY ANY /_profiler/{token}/exception
_profiler_exception_css ANY ANY ANY /_profiler/{token}/exception.css
_twig_error_test ANY ANY ANY /_error/{code}.{_format}
db_transaction_postaddtransaction POST ANY ANY /my_api
db_transaction_gettransactions GET ANY ANY /my_api/
db_transaction_getbalance GET ANY ANY /balance/
homepage ANY ANY ANY /
----------------------------------- -------- -------- ------ -----------------------------------

结果使用:list routes

{  
"web_profiler.controller.profiler":[
"_wdt",
"_profiler_home",
"_profiler_search",
"_profiler_search_bar",
"_profiler_info",
"_profiler_phpinfo",
"_profiler_search_results",
"_profiler_open_file",
"_profiler"
],
"web_profiler.controller.router":[
"_profiler_router"
],
"web_profiler.controller.exception":[
"_profiler_exception",
"_profiler_exception_css"
],
"twig.controller.preview_error":[
"_twig_error_test"
],
"DBBundle\\Controller\\TransactionController":[
"db_transaction_postaddtransaction",
"db_transaction_gettransactions",
"db_transaction_getbalance"
],
"AppBundle\\Controller\\DefaultController":[
"homepage",
"route"
]
}

当我使用命令 php bin\console server:run 启动服务器时,所有路由都有效。

有什么问题以及如何访问 API 方法?

最佳答案

我用了https://phpdocker.io/用于生成文件和作品。

关于mongodb - Docker 中的 Symfony 应用程序在 URL 调用中没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43499343/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com