Docker-使Docker容器使用我的公共IP [英] Docker - Make docker containers use my public ip

查看:133
本文介绍了Docker-使Docker容器使用我的公共IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a react app running inside a container. I need to request an API(not mine) and it only accepts public IP addresses. Can the container use the public address of my machine?

version: '3'

services:

client:
  container_name: client
  build:
    context: ./client
    dockerfile: Dockerfile
  volumes:
    - './client:/usr/src/app'
    - '/usr/src/app/node_modules'
  ports:
    - '3000:3000'
  environment:
    - NODE_ENV=development
    - NODE_PATH=src


推荐答案

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

是的,即使您不指定-net host ,它也可以这样做。您可以使用此图片(或包含 curl ):

Yes, it even does so if you do not specify --net host. You can check that easily using this image (or any other image that contains curl):

首先,在主机上运行它:

First, run this on your host:

curl -s ipinfo.io/ip

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

This will show your current public IP address.

然后,运行容器:

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

它应该导致相同的IP地址。

It should result in the same IP address.

不过,我对React一无所知,因此您可能还会遇到其他问题,但是基本上这不是Docker问题。

I don't know anything about React, though, so there might be other stuff going on in your case, but basically this should not be a Docker problem.

这篇关于Docker-使Docker容器使用我的公共IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆