Dockered tinyproxy for dev environment

The other day I was looking for a solution to replace my Charles based proxy setup for our legacy system’s dev environment. Mostly because a colleague doesn’t have a license and didn’t want to pay for it. And we’re only using it for a single use case. The functionality they call “Map Remote”. Basically it redirects calls to remote services to some other other service making it look like it’s the original system. Ideal for a development system where you can’t just change hostnames (for reasons…).

So what I want to do, I want to type http://foo.example.com in my browser and not end up at the actual example.com live system but instead on services running locally on my computer.

We’ve switched to using docker, so running them locally is a breeze anyway already. So why not just add another docker component that acts as a proxy and does that job for me? I’d then just have to change settings in my browser to make it use that proxy and here I go.
After a short search on duckduckgo I’ve found tinyproxy and after inspecting it a bit deeper I found a way to make it work for me the way I wanted.
Here’s the Dockerfile I came up with, just change the hostnames that suit you and you’re all set.

FROM alpine
MAINTAINER Stefan Strigler 

RUN apk add --no-cache tinyproxy

RUN { \
    echo 'upstream web_app:80 "example.org"'; \
    echo 'upstream web_app:80 ".example.org"'; \
    echo 'upstream some_other:80 "foo.example.org"'; \
    } >> /etc/tinyproxy/tinyproxy.conf

RUN sed -i 's/^Allow/\#Allow/' /etc/tinyproxy/tinyproxy.conf

EXPOSE 8888

ENTRYPOINT /usr/sbin/tinyproxy -d

Since it’s based on alpine the whole image is only less than 5MB. Crazy!

I then added it to our docker-compose.yml like

version: '2'
services:

  web_app: ...

  some_other: ...

  tinyproxy:
    image: steve/tinyproxy
    ports:
      - 8888:8888
    links:
      - web_app
      - some_other


and off we go.

Comments are closed