Docker-使Docker容器使用我的公共IP

时间:2019-04-21 04:16:14

标签: docker docker-compose

问题

我有一个运行在容器中的React应用。我需要请求一个API(不是我的),并且它仅接受公共IP地址。容器可以使用我的机器的公共地址吗?

Docker-compose

THE Mississippi is well worth reading about. It is not a commonplace
river, but on the contrary is in all ways remarkable. Considering the
Missouri its main branch, it is the longest river in the world--four
thousand three hundred miles. It seems safe to say that it is also the
crookedest river in the world, since in one part of its journey it uses
up one thousand three hundred miles to cover the same ground that the
crow would fly over in six hundred and seventy-five. It discharges three
times as much water as the St. Lawrence, twenty-five times as much
as the Rhine, and three hundred and thirty-eight times as much as the
Thames. No other river has so vast a drainage-basin: it draws its water
supply from twenty-eight States and Territories; from Delaware, on the
Atlantic seaboard, and from all the country between that and Idaho on
the Pacific slope--a spread of forty-five degrees of longitude. The
Mississippi receives and carries to the Gulf water from fifty-four
subordinate rivers that are navigable by steamboats, and from some
hundreds that are navigable by flats and keels. The area of its
drainage-basin is as great as the combined areas of England, Wales,
Scotland, Ireland, France, Spain, Portugal, Germany, Austria, Italy,
and Turkey; and almost all this wide region is fertile; the Mississippi
valley, proper, is exceptionally so.

It is a remarkable river in this: that instead of widening toward its
mouth, it grows narrower; grows narrower and deeper. From the junction
of the Ohio to a point half way down to the sea, the width averages a
mile in high water: thence to the sea the width steadily diminishes,
until, at the 'Passes,' above the mouth, it is but little over half
a mile. At the junction of the Ohio the Mississippi's depth is
eighty-seven feet; the depth increases gradually, reaching one hundred
and twenty-nine just above the mouth.

1 个答案:

答案 0 :(得分:0)

关于您的问题:容器可以使用我的机器的公共地址吗?

是的,即使您未指定--net host,它也会这样做。您可以使用this image(或包含curl的任何其他图像)轻松地进行检查:

首先,在主机上运行它:

curl -s ipinfo.io/ip

这将显示您当前的公共IP地址。

然后,运行容器:

docker run --rm appropriate/curl -s ipinfo.io/ip

它应该具有相同的IP地址。

不过,我对React一无所知,因此您的情况可能还会有其他事情发生,但是基本上这应该不是Docker问题。

相关问题