限制 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

相關內容