Docker Community Forums

Share and learn in the Docker community.

Access docker services fro browser or Ajax requests

Hi,

I am trying to access service from Ajax requests like this http://gateway:4000/auth
And my docker-compose file looks as below

version: '2’
services:
UI:
image: arbitrage/ui
restart: always
ports:
- 8182:8182

registry:
image: arbitrage/registry
restart: always
ports:
- 8761:8761
logging:
options:
max-size: "10m"
max-file: “10”

gateway:
image: arbitrage/gateway
restart: always
links:
- registry
ports:
- 4000:4000
logging:
options:
max-size: "10m"
max-file: “10”

I am getting the error

OPTIONS http://gateway:4000/auth net::ERR_NAME_NOT_RESOLVED

What am I missing. Can some one please help

gateway is a name that just resolves within your docker network.
You bind your gateway:4000 to your localhost:4000.

So access it with http://localhost:4000/ should work for you

Hi,
Thanks for response. It is not accessible with http://localhost:4000. I had tried this earlier only.
But if I hard code container ip then it becomes accessible. But I don’t want to hard code IP address.

hard to guess where the problem lies without detailed information about your environment.
I guess you do not have a native docker installation, but are using boot2docker.

Hi,

I have installed docker with Docker ToolBox and my docker ps give this result

$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d2d0eb9471d7 arbitrage/build “java -Xmx200m -jar /” 4 hours ago Up 4 hours 0.0.0.0:6000->6000/tcp services_build_1
c6c2039eb3af arbitrage/ui “npm start” 4 hours ago Up 4 hours 0.0.0.0:8182->8182/tcp services_UI_1
95bd52fec454 arbitrage/gateway “java -Xmx200m -jar /” 4 hours ago Up 4 hours 0.0.0.0:4000->4000/tcp services_gateway_1
807c1defa608 arbitrage/registry “java -Xmx200m -jar /” 2 days ago Up 5 hours 0.0.0.0:8761->8761/tcp 807c1defa608_services_registry_1

Like , this works for me
http://192.168.99.100:4000/auth

If we want to access UI on my docker instance from others browser , it does not work.