Suppose I have a server running on port 8000 on Windows. How can my Docker container access it via 127.0.0.1:8000? I can't change the hostname too as the app in the container is not in my control.
I've read this previous discussion same but inside VB on using "--network=host" for a container to access the host machine's network, or using some different ip for the localhost. However, I'm on Windows and Docker runs inside a Windows Subsystem for Linux (ubuntu from the windows store) so localhost from the Docker container with --network="host" does not get it right. From inside the Windows Subsystem for Linux I can access 127.0.0.1:8000 without problems.
For instance, having some bash file doing the following
#!/bin/bash
set -x
# we get some file from the localhost
curl 127.0.0.1:22334/some_file.txt
# we build docker image
docker build --tag dockername --network=host dockerfiles/imagename
and some docker file like this
# This is a Dockerfile
FROM ubuntu:16.04 as installer
RUN apt-get update && apt-get install --no-install-recommends curl -y
RUN curl 127.0.0.1:22334/some_file.txt
I get something like
+ curl 127.0.0.1:22334/some_file.txt
here_we_get_some_file_content
+ docker build --tag dockername --network=host dockerfiles/imagename
Sending build context to Docker daemon 18.43kB
Step 1/30 : FROM ubuntu:16.04 as installer
---> 4a689991aa24
Step 2/30 : RUN apt-get update && apt-get install --no-install-recommends curl -y
---> Running in 72378a1be045
...
Step 3/30 : RUN curl 127.0.0.1:22334/some_file.txt
---> Running in 41a4c470337b
curl: (3) <url> malformed
The command '/bin/sh -c curl 127.0.0.1:22334/some_file.txt' returned a non-zero code: 3