I have a python flask application that is running in a docker container. I have the following code in my flask app:
status.route("/ipaddr", methods=["GET"])
@jwt_required()
def get_external_ip():
result = subprocess.check_output("ifconfig | grep enp1s0 -A 1 | grep 192 | awk '{print $2}'", shell=True)
return jsonify(ip_address=result.decode('utf-8').strip())
The command inside check_output is correct. My problem is, this is returning the IP address of the docker image and not the server. I need the IP of the server that comes out as output of this command. When I ran this command in my server bash, it works fine and gives me what i want but since flask is running inside docker, it is not giving me the IP I want. So, my question is: how do I run this command in the SERVER while my flask app is running in a docker container inside that server?
Thanks.