[nginx] From inside of a Docker container, how do I connect to the localhost of the machine?

This is not an answer to the actual question. This is how I solved a similar problem. The solution comes totally from: Define Docker Container Networking so Containers can Communicate. Thanks to Nic Raboy

Leaving this here for others who might want to do REST calls between one container and another. Answers the question: what to use in place of localhost in a docker environment?

Get how your network looks like docker network ls

Create a new network docker network create -d my-net

Start the first container docker run -d -p 5000:5000 --network="my-net" --name "first_container" <MyImage1:v0.1>

Check out network settings for first container docker inspect first_container. "Networks": should have 'my-net'

Start the second container docker run -d -p 6000:6000 --network="my-net" --name "second_container" <MyImage2:v0.1>

Check out network settings for second container docker inspect second_container. "Networks": should have 'my-net'

ssh into your second container docker exec -it second_container sh or docker exec -it second_container bash.

Inside of the second container, you can ping the first container by ping first_container. Also, your code calls such as http://localhost:5000 can be replaced by http://first_container:5000

Examples related to nginx

Kubernetes service external ip pending nginx: [emerg] "server" directive is not allowed here Disable nginx cache for JavaScript files Nginx upstream prematurely closed connection while reading response header from upstream, for large requests Nginx: Job for nginx.service failed because the control process exited How can I have same rule for two locations in NGINX config? How to verify if nginx is running or not? Find nginx version? Docker Networking - nginx: [emerg] host not found in upstream How do I rewrite URLs in a proxy response in NGINX

Examples related to docker

standard_init_linux.go:190: exec user process caused "no such file or directory" - Docker What is the point of WORKDIR on Dockerfile? E: gnupg, gnupg2 and gnupg1 do not seem to be installed, but one of them is required for this operation How do I add a user when I'm using Alpine as a base image? docker: Error response from daemon: Get https://registry-1.docker.io/v2/: Service Unavailable. IN DOCKER , MAC How to fix docker: Got permission denied issue pull access denied repository does not exist or may require docker login Docker error: invalid reference format: repository name must be lowercase Docker: "no matching manifest for windows/amd64 in the manifest list entries" OCI runtime exec failed: exec failed: (...) executable file not found in $PATH": unknown

Examples related to reverse-proxy

Nginx reverse proxy causing 504 Gateway Timeout From inside of a Docker container, how do I connect to the localhost of the machine? Error during SSL Handshake with remote server Configure Nginx with proxy_pass nginx - read custom header from upstream server Proxy with express.js How to serve all existing static files directly with NGINX, but proxy the rest to a backend server. What's the difference between a proxy server and a reverse proxy server?

Examples related to docker-networking

What does --net=host option in Docker command really do? Docker Networking - nginx: [emerg] host not found in upstream From inside of a Docker container, how do I connect to the localhost of the machine? How can I expose more than 1 port with Docker?