Vishakha Lall
Vishakha Lall

Reputation: 1314

Access localhost during Docker Build MacOS host.docker.internal throws Connection Refused error

I am building my docker image on Docker for Mac where I need to install some gems from the local gem repository hosted on localhost:9292.

I have this in my Dockerfile

RUN gem install patron -v 0.10.0 --source http://host.docker.internal:9292

However, the gem install does not complete and throws a Errno::ECONNREFUSED: Connection refused error. I also tried to curl to the host.docker.internal and that throws an error Failed to connect to host.docker.internal port 9292: Connection refused

Where am I going wrong?

Upvotes: 0

Views: 3216

Answers (2)

Muhammad Hasan
Muhammad Hasan

Reputation: 168

try --add-host=google.com:127.0.0.1 in your build command. It worked for me in ubuntu. I was able to see the ip to google.com as specified in the cmd. just replace the dns and ip

for your case:

--add-host=host.docker.internal:127.0.0.1

Upvotes: 0

Konrad Botor
Konrad Botor

Reputation: 5053

According to the documentation host.docker.internal works only in development (although I do not know how Docker daemon determinse if it's running on production or not). My guess is that your Docker daemon runs in production mode.

Upvotes: 1

Related Questions