0

I've got a docker container running an app that needs to proxy requests from itself, to itself to my host machine running an instance of a theme that shares data between the theme and the app. So the app can be used across multiple themes using the relative theme data.

Anyway, I've got an image built using the below Dockerfile

FROM node:12-alpine

EXPOSE 3006

RUN apk update && apk upgrade

RUN apk add \
    bash \
    git \
    openssh

RUN npm install -g -y lerna

Then I create a container using

docker create -it -p 3006:3006 --name=testing -v $(pwd)/build:/build

The container is then started and the app is started using

PORT=3006 react-scripts-ts start screen

Which exposes the app through the container on port 3006. To proxy requests to itself, the package.json file is set as such

{
  "proxy": "http://192.168.1.101:3000"
  // Rest of file
}

^ This above setup works but this project is worked on by multiple developers, my concern is that when this is run on a different setup or the host machines local IP isn't 192.168.1.101 then it'll fail.

I've tried setting it to the below

{
  "proxy": "http://localhost:3000"
  // Rest of file
}

but this fails as presumably this is proxying the requests to the localhost of the container, not the host machine. So essentially my question, in simplistic terms is can I tell a docker container to proxy/reroute a request to localhost (or localhost:3000) to my host machines localhost?

  • add the flag option --net=host in your docker run command after that you should be able to use the localhost:3000 – Gautam Malik Dec 08 '20 at 20:15
  • Have you read through [From inside of a Docker container, how do I connect to the localhost of the machine?](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach), which gives most of the available approaches? (Host networking generally disables Docker's networking stack and I'd consider it a last resort if nothing else works.) – David Maze Dec 08 '20 at 22:17

0 Answers0