Find host ip address from docker container running in boot2docker / osx

I just tried moving the application to the docker container using boot2docker in OS X.

For this application, you need to connect to the mysql server running on the main system (not in the application container or in another container).

Now I am struggling with setting up the mysql name in the docker application: for now, it is simply connected to localhost, but this no longer works because it no longer indicates that mysql is actually running.

As a quick workaround, I added my private IP workstations (10.0.0.X in my case) to the mysql connection configuration of the application.

However, I wonder: Is there an automatic way to find the private host IP address from the docker container?

+5
source share
1 answer

You can provide the IP and port through environment variables for the contained application.

Create a script in your container, for example:

#!/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 eg in your app config. 

Launch your container with:

 docker run -e MYSQL_HOST=192.168.172.1 MYSQL_PORT=3306 your_image 

Take a look, for example. http://serverascode.com/2014/05/29/environment-variables-with-docker.html

+2
source

All Articles