Docker: Simplified container mapping for local development
When you are working with docker on your local machine, you often have to map your local ports to different container and end up in a port-mapping-mess like this:
- localhost:80 -> Local apache for native stuff
- localhost:8080 -> Docker container with apache for testing
- localhost:8100 -> Some sort of dockered WebApp
- …
- localhost:59924 -> “Yea, well … don’t know, lets check docker process-list …”
To simplify this mess, we created a little proxy-script (+ environment setup) that will make your life much easier: https://github.com/netz98/docker-router-proxy
The router proxy will add the ability to dispatch your request based on the container name. To archive this, it adds a special TLD which will be used to determine that we want to call an docker container.
In our case (default) this will be .dock, but you can choose a different one if you like.
After configuring the environment (as described within the project description on GitHub) you can simply call your container like this:
http://my-service-container.dock
this will be proxied to
0.0.0.0:8999->80/tcp my_service_container
I’m using this script now for several days and it’s absolutely worth the time for setting up the environment. It’s very easy now to navigate through your services and projects just using your browser history.
I’m very interested what you think about this approach and if you might have found other solutions for this?
So, please leave a comment!
– 17 years of experience in the PHP ecosystem
– caffein addicted
– Senior Software Architect at netz98
2 thoughts on “Docker: Simplified container mapping for local development”
Hello everyone,
I am using a similar approach, using this container:
https://github.com/jwilder/nginx-proxy
For that i give the “router” container a fixed IP and put it into my hosts file.
Greetings
Elias
Hello Elias,
thanks for the Reply!
The Nginx-approach is interesting, I’ll check it out and write an update for this post maybe.
I like the idea of explicitly defining the containers domain name using ENV-vars.
Greetings,
Simon