I have just attempted to move an app into a docker container using boot2docker on OS X.
This app requires to connect to a mysql server running on the host system (not in the app's container or in another container).
Now I'm struggling with configuring the mysql hostname within the "dockerized" app: So far it just connected to localhost, but this doesn't work anymore because this no longer points to the host mysql is actually running on.
As a quick workaround, I have added my workstations private IP (10.0.0.X in my case) to the app's mysql connection config.
However I wonder: Is there an automatic way to find the host's private IP address from within a docker container?
You can provide the IP and port through environment variables to the contained application.
Create a script in your container like:
#!/bin/bash
export $MYSQL_HOST
export $MYSQL_PORT
echo $MYSQL_HOST
echo $MYSQL_PORT
# TODO: maybe your have to write some config files at this point
/start_your_app.sh # use the enviroment variables e.g. in your app config.
Run your containerimage with:
docker run -e MYSQL_HOST=192.168.172.1 MYSQL_PORT=3306 your_image
Have a look at e.g. http://serverascode.com/2014/05/29/environment-variables-with-docker.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With