4
我想補充我的MongoDB的Symfony的應用程序的代碼在碼頭工人的形象。
後,我建立應用程序的形象和我recived:
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消息:
泊塢窗,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
結果對於命令
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
叫我recive在郵差
而且在控制檯:
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方法?
評論不適用於擴展討論;這個談話已經[轉移到聊天](http://chat.stackoverflow.com/rooms/143018/discussion-on-question-by-adrian-i-symfony-app-in-docker-doesnt-respond-in- URL)。 –
此外,如果解決了問題,可以考慮添加一個答案,詳細解釋如何解決問題。 –