3

I want to get docker host machine ip address and interface names i.e ifconfig of docker host machine. instead im getting docker container ip address on doing ifconfig in docker container.

It would be great if someone tell me to fetch ip address of docker host machine from a docker container.

i have tried doing ifconfig dockerhostname, as a result i get error dockerhostmachi: error fetching interface information: Device not found

This is my dockerfile

FROM ubuntu:14.04

Install dependencies

RUN apt-get update && apt-get install -y \ python-dev \ libffi-dev \ libssl-dev \ python-enum \ apache2 \ libapache2-mod-wsgi \ python-pip \ python-qt4

RUN chmod -R 777 /var/log/apache2/error.log
RUN chmod -R 777 /var/log/apache2/other_vhosts_access.log
RUN chmod -R 777 /var/log/apache2/access.log
RUN chmod -R 777 /var/run/apache2/

RUN a2enmod wsgi

i need to get ifconfig result for docker host machine from a docker container or when i run docker image.

2
  • If you're building a graphical application that needs host-level configuration details, you will find it vastly easier to run without Docker. Details of the host network are intentionally hidden from your container, by design; running graphical applications also involves jumping through several hoops with subtle failure modes. Commented May 27, 2019 at 11:01
  • I am using docker to bind all the dependencies ,so that i can load docker image on another machine and without internet ill be able to deploy the application and its dependencies. and coming to docker host machine ip, i am able to ping to it from container but not able get details of interfaces and ip address of it. Commented May 27, 2019 at 11:57

2 Answers 2

0

When you run docker image/container you can specify an environment variable using -e parameter. Do it maybe like: docker run -e ip=docker_host_ip ...

then it should be available on container side as environment variable.

https://medium.com/the-code-review/top-10-docker-run-command-options-you-cant-live-without-a-reference-d256834e86c1

Sign up to request clarification or add additional context in comments.

Comments

0

The answer to above question is follows .

  1. METHOD :you can create your own network and communicate with it.

$ sudo docker network create --driver=bridge --subnet=192.168.10.0/24 --gateway=192.168.10.1 doc1net
or
$ sudo docker network create --driver=bridge --subnet=10.45.0.0/24 --gateway=10.45.0.0 doc1net

Here sub-net and gateway can be your own network address and doc1net is a my network name.

2 METHOD

While running the docker connect with your network host.

$ sudo docker network ls
gives you list of your networks.

$ sudo docker run -it --network=host myimage
Here myimage is name of the image i have created

2nd method worked for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.