Score:0

Access the host's IP or loopback interface from Docker container

ng flag

willnorris/imageproxy is a caching image proxy server that we use in one of our deployments. We typically have a PHP backend that will serve some html or json to a client where the URL would be http://<imageproxy>/200/https://willnorris.com/logo.jpg. Then the client will fetch that image from the proxy. This is fine.

What I cannot get working is doing this in local development using Docker (Compose). The problem is that, unlike production, the domain I want to fetch images from is running on the host, typically only exposed on the loopback interface (127.0.0.*). I typically define an entry in my /etc/hosts folder that is something like

127.0.0.2 web.myproj admin.myproj cdn.myproj

And then I access web.myproj on that computer. How would I get the Docker container to connect to the localhost address of its host (whatever this is called in Docker lingo)? I suppose I can use the extra_hosts feature somehow?

If specifically connecting to a reserved loopback address/localhost is not possible/permitted, is there another way to access an ip of the host?


Tech details

  • Host: Ubuntu 21.04 running inside a VMWare Workstation on Windows 10 Pro
Michael Hampton avatar
cz flag
Is this Docker running on WSL2 or on an actual Linux machine?
ng flag
It's normally running on macOS and "real" Linux when developing.
Michael Hampton avatar
cz flag
Do you mean a Linux virtual machine?
ng flag
No, I switch workstations :) At work I have a Windows computer where I run Linux in a VM (and WSL2, for that matter, but not all apps work equally well) and at home I run macOS.
Michael Hampton avatar
cz flag
This is technology, not magic, and as such I can't read either your computer or your mind. It's best to be as detailed as possible when answering such questions, so that people tryiing to help you are not confused by relevant information being missing, nor taking up unnecessary time trying to ask for clarification. That said, here are my questions for clarification: Do you mean that you connect to the Linux VM at work when using macOS at home? What about WSL2? Which one (or both) are you actually using here for this project?
ng flag
Sure, totally understand that. I was not trying to offend you in any way. I'll scope the question down to Linux. Details added now :)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.