I'm new in docker. Let me describe my scenario: I made 2 docker images for a web application. one image is front-end web layer for presentation and the other is back-end layer supplying REST service.
So I need to run 2 containers for this 2 images. the front-end calls services in back-end. Now I need to write the back-end's URL in front-end's code and build the image...I don't think this is the right way for micro service...
because if my laptop's IP changes or others want to use my image,they cannot get the service...So how can I make the URL variable and make my front-end image can be used for others without rebuild?
Thx!
You can do this by passing an environment variable to the docker container when you run it.
something like this:
docker run --name frontend -e MY_APP_BACKEND_IP="192.168.7.2" -e MY_APP_BACKEND_PORT="3000" ...
And on the back-end, let's say you are using NodeJS, you can do:
var backend_ip = process.env.MY_APP_BACKEND_IP;
Note: Not a NodeJS pro, but some googling showed me how to do it