Docker - Make docker containers use my public ip

混江龙づ霸主 提交于 2019-12-13 05:06:48

问题


Problem

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?

Docker-compose

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

回答1:


As to your question: Can the container use the public address of my machine?

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

This will show your current public IP address.

Then, run the container:

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

It should result in the same IP address.

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.



来源:https://stackoverflow.com/questions/55779832/docker-make-docker-containers-use-my-public-ip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!