diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f63adff --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +# official python image +FROM python:3.9-slim + +# setting working dir +WORKDIR /localfiletransfer + +# copy flask app in to the container +COPY . /localfiletransfer + +# installing requirements +RUN pip install --no-cache-dir -r requirements.txt + +# exposing port 5000 +EXPOSE 5000 + +# command to run the app +CMD [ "python3", "app.py" ] diff --git a/app.py b/app.py index a281463..413697a 100644 --- a/app.py +++ b/app.py @@ -55,16 +55,10 @@ def download_file(filename): return response def get_ip(): - s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) try: - # doesn't even have to be reachable - s.connect(('10.255.255.255', 1)) - IP = s.getsockname()[0] - except Exception: - IP = '127.0.0.1' - finally: - s.close() - return IP + return socket.gethostbyname("host.docker.internal") # Host IP For macOS and Windows + except: + return socket.gethostbyname(socket.gethostname()) # Host IP For Linux def generate_qr_code(url): qr = qrcode.QRCode( diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e5cbe3a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,22 @@ +version: '3.9' + +services: + + web_windows: # service for Windows/Mac + build: . + volumes: + - ./uploads:/localfiletransfer/uploads + - ./downloads:/localfiletransfer/downloads + ports: + - "5000:5000" # Required for macOS/Windows to expose the container port + profiles: + - "windows_mac" # Profile name for macOS/Windows + + web_linux: # service for Linux + build: . + volumes: + - ./uploads:/localfiletransfer/uploads + - ./downloads:/localfiletransfer/downloads + network_mode: "host" # Linux host network mode + profiles: + - "linux" # Profile name for Linux