Docker中的Symfony应用程序在URL调用中不响应

[解决了]

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

在我build立应用程序的形象后,我收回:

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,我recive在邮递员的消息:

在这里输入图像说明

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 

并且命令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打电话时,我在邮差中收回

在这里输入图像说明

在控制台中:

 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 / ----------------------------------- -------- -------- ------ ----------------------------------- 

结果使用: 列出路线

 { "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启动服务器时php bin\console server:run所有的路由工作。

什么是错的,我如何访问API方法?