As a follow up to Linking Docker Containers
I've linked both a mongo, redis container with my nodejs app container successfully. My node app is now running inside my container but for some reason I can't access it:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3f8790bb7cc5 mseay/myapp:latest "/bin/bash" 2 minutes ago Up 2 minutes 0.0.0.0:3000->3000/tcp myapp
5470cdd876eb redis:latest "/entrypoint.sh redi About an hour ago Up About an hour 6379/tcp redis
36c61197d8bd mongo:latest "/entrypoint.sh mong About an hour ago Up About an hour 27017/tcp mongo
Inside my container, my node app is running on port 3000. My docker run command specifies to map 3000 in my container to 3000 on my host:
docker run -i -t -p 3000:3000 --name myapp --link mongo:MONGODB --link redis:REDIS mseay/myapp /bin/bash
docker port shows
3000/tcp -> 0.0.0.0:3000
But, when I goto localhost:3000 or try to curl it:
curl: (7) Failed to connect to localhost port 3000: Connection refused
Apologies for being noobish. Any help is always greatly appreciated!
The issue is that you're using boot2docker
. The ports are published on the virtual machine running docker. You can get the ip address of that vm by running boot2docker ip
.
So, for your service on port 3000, you could run:
curl http://$(boot2docker ip):3000/