We have a team of developers using MacBook Pros for development, and they have to travel from one office to another. When the laptop joins the WIFI network at a different location, a brand new IP address is allocated. This should be an issue for most docker containers running on the laptop except Kafka as it has to advertise to DOCKER_HOST_IP.
We can use ifconfig to find the real IP address and export it with the following command.
After that, we can stop and restart the docker-compose for eventuate local environment. It is doable but not very convenient. To allow developers to start the eventuate docker-compose only once and use it until the laptop is rebooted, we need to find a way to set up a fixed IP address for the MacBook Pro.
On Mac, you can use the following command to create an alias network interface and assign a fixed IP to it.
sudo ifconfig lo0 alias 10.200.10.1/24 # an unused IP address
Once this is done, you can use the above export command to bind this IP to DOCKER_HOST_IP and pass it to the Kafka docker container. It works until you restart your laptop. How can we make it into the startup script so that we don’t need to remember that every time you restart your computer?
We can put the export command into .profile file under home directory. But the command to create an alias is executed with sudo.
For this special case, we need to utilize launchd to kick off a short script with the ifconfig command you used above.
Here is a sample .plist file, saved as com.user.lo0-loopback.plist (can be saved anywhere as it will be copied to the appropriate directory later).