소스 검색

Dockerfile and image (#10)

* working docker image.

* add readme reference.

* Added env var

* Updated pip package name

* Update README.md with precision with bridge and docker.
NMC 6 년 전
부모
커밋
fd6c8a978d
3개의 변경된 파일46개의 추가작업 그리고 0개의 파일을 삭제
  1. 13 0
      Dockerfile
  2. 21 0
      README.md
  3. 12 0
      main.py

+ 13 - 0
Dockerfile

@@ -0,0 +1,13 @@
+FROM python:3.8-alpine
+
+RUN apk add iproute2
+
+RUN pip3 install Flask
+
+ENV TCGUI_IP=0.0.0.0
+
+WORKDIR /app
+
+COPY . /app
+
+CMD ["python3", "main.py"]

+ 21 - 0
README.md

@@ -32,6 +32,27 @@ No further changes are planned right now, but pull requests are welcome.
 
 - The tool will read your interfaces and the current setup every time the site is reloaded
 
+## Docker
+
+You can use docker to run this application. Run with host network (`--network host`) and network admin capabilities (`--cap-add=NET_ADMIN`). Site will be available on default port Ex: `http://dockerhost:5000`
+
+    docker run -dit --restart unless-stopped --network host --cap-add=NET_ADMIN ncareau/tcgui:latest
+
+
+You can change the configuration using these Environment Variables:
+
+* **TCGUI_IP** - *Default `0.0.0.0`* - Use to change listening address
+* **TCGUI_PORT** - *Default `5000`* - Use to change the listening port
+* **TCGUI_DEV** - The interfaces to restrict to
+* **TCGUI_REGEX** - A regex to match interfaces
+
+If using an interface bridge, docker might cause issue with the bridge. (https://askubuntu.com/questions/1073501/docker-breaks-network-bridging-to-virtual-machines)
+To fix this, create a file `/etc/docker/daemon.json` with the following contents:
+
+	{
+	    "iptables" : false
+	}
+
 ## Test & Develop
 
 You can use the supplied Vagrantfile to test tcgui quickly. Vagrant will setup two machines, sender (192.168.210.2) and a receiver (192.168.210.3):

+ 12 - 0
main.py

@@ -178,12 +178,24 @@ if __name__ == "__main__":
         print("You need to have root privileges to run this script.\n"
               "Please try again, this time using 'sudo'. Exiting.")
         exit(1)
+
+    # TC Variables
     args = parse_arguments()
+
+    pattern = os.environ.get("TCGUI_REGEX")
     if args.regex:
         pattern = re.compile(args.regex)
+    
+    dev_list = os.environ.get("TCGUI_DEV")
     if args.dev:
         dev_list = args.dev
+
+    # Flask Variable
     app_args = {}
+
+    app_args['host'] = os.environ.get("TCGUI_IP")
+    app_args['port'] = os.environ.get("TCGUI_PORT")
+
     if args.ip:
         app_args['host'] = args.ip
     if args.port: