alireza0 / s-ui

An advanced Web Panel • Built for SagerNet/Sing-Box
https://t.me/XrayUI
GNU General Public License v3.0
2.15k stars 307 forks source link

How to install sing-box core container with host network, to use any port conveniently. #127

Closed leic4u closed 1 month ago

leic4u commented 1 month ago

I tried compose.yml like this, but it seems that the sing-box core could not work, with my config in s-ui panel:

---
version: "3"

services:
  s-ui:
    image: alireza7/s-ui
    container_name: s-ui
    hostname: "S-UI docker"
    volumes:
      - "singbox:/app/bin"
      - "$PWD/db:/app/db"
      - "/root/nginx-ui/nginx/ssl/:/app/cert"
    environment:
      SINGBOX_API: "sing-box:1080"
      SUI_DB_FOLDER: "db"
    tty: true
    restart: unless-stopped
    ports:
      - "127.0.0.1:32095:2095"
      - "127.0.0.1:32096:2096"
    networks:
      - s-ui
    entrypoint: "./sui"

  sing-box:
    image: alireza7/s-ui-singbox
    container_name: sing-box
    volumes:
      - "singbox:/app/"
      - "/root/nginx-ui/nginx/ssl/:/cert"
    network_mode: host
    restart: unless-stopped
    depends_on:
      - s-ui

networks:
  s-ui:
    driver: bridge

volumes:
  singbox:

How could I use the all ports conveniently? Or could you please provide a image which contains both panel and core?

alireza0 commented 1 month ago

You should use network_mode: host in both s-ui and sing-box containers and remove ports sections.

leic4u commented 1 month ago

Hey bro. I could use the any port by installing s-ui with this config:

---
services:
  s-ui:
    image: alireza7/s-ui
    container_name: s-ui
    hostname: "S-UI docker"
    volumes:
      - "singbox:/app/bin"
      - "$PWD/db:/app/db"
      - "/root/nginx-ui/nginx/ssl:/cert"
    environment:
      SINGBOX_API: "localhost:1080"
      SUI_DB_FOLDER: "db"
    tty: true
    restart: unless-stopped
    network_mode: "host"
    entrypoint: "./sui"

  sing-box:
    image: alireza7/s-ui-singbox
    container_name: sing-box
    volumes:
      - "singbox:/app/"
      - "/root/nginx-ui/nginx/ssl:/cert"
    network_mode: "host"
    restart: unless-stopped
    depends_on:
      - s-ui

volumes:
  singbox:
leic4u commented 1 month ago

When I use host, an error message appears in the sing-box container. "start service: start v2ray api: listen tcp: lookup sing-box on 192.168.1.1:53: no such host" Do you know how to solve it?

Looks like the Docker routing rules were not created correctly. You can try restarting the Docker service.

dycwuxing commented 1 month ago

Looks like the Docker routing rules were not created correctly. You can try restarting the Docker service.

Yes, I used wrong information in sing-box's api reference, I have solved it, thanks for your answer