限制docker容器仅监听本地子网访问

限制docker容器仅监听本地子网访问

我看到了这个:https://stackoverflow.com/questions/56053824/how-to-restrict-that-a-docker-container-only-listens-connection-from-localhost

docker run -p 127.0.0.1:8080:8080 your_image_name

但我想限制对本地子网的访问,例如127.0.0.*。我必须为此设置 iptables 过滤器吗?

PS 有些具有特定端口的容器仍然需要访问外部互联网:

  mycontainer:
    image: myimage:latest
    container_name: mycontainer
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Etc/UTC
      - WEBUI_PORT=8080
    volumes:
      - <>:/config
      - <>:/downloads
    ports:
      - 8080:8080         # < need to restrict to local subnet
      - 50016:50016
      - 50016:50016/udp   # <---- still needs outside access!
    restart: unless-stopped

相关内容