问题
This is related to the stackoverflow question here: Run Websocket on GAE .
I am trying to run a version of mozilla's browserquest in a sandbox google custom runtime nodejs environment with boot2docker parameters as follows:
docker version
Client version: 1.5.0
Client API version: 1.17
Go version (client): go1.4.1
Git commit (client): a8a31ef
OS/Arch (client): darwin/amd64
Server version: 1.5.0
Server API version: 1.17
Go version (server): go1.4.1
Git commit (server): a8a31ef
I've controlled for quite a few potential errors, including shifting the server to port 8001 and exposing that port to avoid the conflict with the 8000 port that is reserved for the google app engine admin.
However I am currently stuck since, as far as I understand it, to succeed in this task I would need to provide the ip of my server to my application in order to use websockets (for clarification on this issue, see https://github.com/jdeskins/socketio-gcmvm and the comment in the readme.md therein about using http://[DOCKER-IP]:3000 rather than http://localhost:3000, say to check).
In particular, I was wondering if there are any elegant or simple techniques to configure the dockerfile, or alter some other configuration setting, or determine the ip, so that one can automatically point an application using websockets (such as browserquest) to the right ip when the client tries to connect to the websocket on the server.
Ultimately what I'd be after is something I can add to my project so that when I type
gcloud preview app run .
and then point my browser to http://localhost:8080, I will be able to step into the game (running npm start from my main project directory and then opening the entry point for the web application (index.html within the /client folder) works).
回答1:
Taken from the OP's comment :
I found a way around this - if one enters in the ip manually (for local development, running boot2docker ip gives the ip required, and for production, ping http://.appspot.com gives the ip required in that instance. So this problem can be worked around, it would however be useful perhaps to find a way to read off the ip of the docker container from within it so that one could automate the process of configuring the ip address to point the application to when making server requests
来源:https://stackoverflow.com/questions/28559921/google-app-engine-ip-of-docker-custom-runtime-container-node-js