Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get docker0 ip address platform independently

Tags:

docker

I'm building application which needs to have ip address of docker0 without using commands like ip addr show dev docker0. Is there any way to get it from docker itself maybe using docker command or something else? At least the docker info doesn't seem to show it.

like image 769
Henri Koski Avatar asked Jul 18 '17 08:07

Henri Koski


2 Answers

docker0 network interface is associated with the default docker network bridge.
You can access info about it with the docker network inspect bridge.
You can use the --format option to get specific value:

$ docker network inspect bridge --format='{{json .IPAM.Config}}'
[{"Subnet":"172.17.0.0/16","Gateway":"172.17.0.1"}]
like image 81
zigarn Avatar answered Sep 23 '22 04:09

zigarn


Get just the gateway ip with:

$ docker network inspect bridge --format='{{(index .IPAM.Config 0).Gateway}}'
172.17.0.1
like image 30
Filidor Wiese Avatar answered Sep 20 '22 04:09

Filidor Wiese