Accessing localhost from dockerfile during build

Hi,

I try to write a dockerfile for a multistage build, first step compile in one image, second step install in new image. Nothing special.

The problem is getting the source code into the first step for compilation. The repository is in a Gitea container that I can access in my browser using localhost:3000. So I tried

RUN git clone http://localhost:3000/my/repo.git

but I get

Failed to connect to localhost port 3000: Connection refused

Of course I could clone the repo out of the container any use copy, but I would like to avoid that.

After searching google for help I tried

RUN git clone http://host.docker.internal:3000/my/repo.git

as well as using the build option

--network=host

and

--network=services_gitea

which is the network I assigned in compose (+ prefix), and replacing localhost with the alias.

Non of this worked, and I saw later in the reference for docker build that the --network option is a setting for runtime and not buildtime. I have a windows host, so I assume it might be a problem with the background vm docker is running, and thus localhost not pointing to the host but the vm (?).

I hope someone here can help me.

Regards

Thorsten

Howdy, did you ever get this to work? I am trying to do something similar, but am getting connection refused error as well.

using host.docker.internal instead of localhost worked like a charm for me.

1 Like