user2309838
user2309838

Reputation: 307

expose docker container's application url to host

I have a docker image with some ruby on rails environment built in (i.e. installing some rails gems and system packages) and I have an EXPOSE 3000 to expose the port at the end.

I ran a container with docker run -p 3000:3000 -ti <image> bash, then start the rails server. The logs are saying the web server is available on localhost:3000. I tried to connect to both the IPAddress as specified in docker inspect <id> and localhost on my host machine, but neither would be able to connect. What could be the problem here?

Upvotes: 0

Views: 1252

Answers (1)

Leonardo Dagnino
Leonardo Dagnino

Reputation: 3215

If your application is listening on localhost, it will only respond to requests from the container's localhost - that is, other processes inside the container.

To fix this you need to set the listen address of your server to listen to any address (usually, you specify this as 0.0.0.0). I've never used rails, but from a quick search, you should use the -b option.

So changing your ENTRYPOINT or CMD in your Dockerfile to contain -b 0.0.0.0 would probably do it.

Upvotes: 1

Related Questions