docker中的gradio無法存取

最近執行一個專案,會在docker容器中安裝grdio,一個可以快速建構的web gui

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

執行預設會在port 7860,docker-compose.yaml中是這樣把port連進去的

        ports:
            "7860:7860"

但實際存取後發現無法訪問,如下
所以我一開始只能用public url進去使用

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

找了很久問題一直以為是防火牆的原因
問了chatgpt也找不到正解==
後來用了別的程式才發現根本沒有防火牆的問題存在XD
所以上網查了一下才知道要特別指定environment變數,如下

        environment:
          - GRADIO_SERVER_NAME=0.0.0.0
          - GRADIO_SERVER_PORT=7860

最終修改完的docker-compose.yaml (for MobileSAM)

services: mobilesam: stdin_open: true tty: true devices: - /dev/dri volumes: - .:/root/MobileSAM ports: - "7860:7860" deploy: resources: reservations: devices: - driver: nvidia count: all capabilities: - gpu environment: - QT_X11_NO_MITSHM=1 - NVIDIA_VISIBLE_DEVICES=all - NVIDIA_DRIVER_CAPABILITIES=all - GRADIO_SERVER_NAME=0.0.0.0 - GRADIO_SERVER_PORT=7860 container_name: mobilesam-container build: . image: frakw/mobilesam:latest command: /bin/bash