Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Docker Flask App on windows system
#1
Hello!

I'm trying to build a flask chat app but facing following issue (on windows)

sending post and get requests works fine locally through
127.0.0.1 - - [26/Oct/2024 16:54:56] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [26/Oct/2024 16:55:17] "POST /send-message HTTP/1.1" 200 -


but as soon as the app is made into a docker container
the app opens through localhost:5000 and 127.0.0.1:5000 but port 172.17.0.1:5000 refuses to connect.
when request is run through localhost:5000 or 127.0.0.1:5000 the docker app automatically routes it through
172.17.0.1 - - [26/Oct/2024 16:54:56] "GET / HTTP/1.1" 200 -
172.17.0.1 - - [26/Oct/2024 16:55:17] "POST /send-message HTTP/1.1" 200 -
which does not get the response.

is there a way to get the 172.17.0.1 to connect or a way to route the post and get through 127.0.0.1 how to change the docker default

from
172.17.0.1 - - [26/Oct/2024 16:54:56] "GET / HTTP/1.1" 200 -

172.17.0.1 - - [26/Oct/2024 16:55:17] "POST /send-message HTTP/1.1" 200 -

Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
FROM python:3.10-slim
 
#container workdir
WORKDIR /app
 
#install chromium and dependencies
RUN apt-get update && apt-get install -y \
    chromium \
    chromium-driver \
    libglib2.0-0 \
    libnss3 \
    libx11-xcb1 \
    libxcomposite1 \
    libxcursor1 \
    libxdamage1 \
    libxext6 \
    libxfixes3 \
    libxi6 \
    libxrandr2 \
    libxrender1 \
    libdbus-glib-1-2 \
    libatk1.0-0 \
    libatk-bridge2.0-0 \
    libfontconfig1 \
    libx11-6 \
    libx11-xcb-dev \
    libxcb1 \
    libxss1 \
    fonts-liberation \
    libappindicator3-1 \
    xdg-utils \
    wget \
    unzip \
    && rm -rf /var/lib/apt/lists/*
 
RUN chmod +x /usr/bin/chromium && chmod +x /usr/bin/chromedriver
 
#copy dir contents to container
COPY . /app
 
#install packages
#RUN pip install -r requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
 
#expose app port
 
ENV HOST=0.0.0.0
ENV LISTEN_PORT 5000
EXPOSE 5000
 
#headless
ENV CHROME_BIN=/usr/bin/chromium
ENV CHROMEDRIVER_PATH=/usr/bin/chromedriver
 
#run
ENV FLASK_APP=app_local_new.py
ENV FLASK_ENV=production
 
#tested commands
CMD ["gunicorn", "-b", "0.0.0.0:5000""app_local_new:app"]
#CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:5000", "--preload", "app_local_new:app"]
#CMD gunicorn -b 0.0.0.0:${PORT:-5000} "app_local_new:app"
docker-compose.yml
1
2
3
4
5
6
7
8
9
10
11
12
version: "3"
services:
  app_local_new:
    build: .
    ports:
      - "5000:5000"
    networks:
      - app-networks
 
networks:
  app-networks:
    driver: bridge
app_local_new.py
1
2
3
4
5
@app.route('/send-message', methods=['POST'])
def send_message():
    data = request.get_json()
    user_message = data.get('userMessage', '')
    print(user_message)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python flask uwsgi nginx docker mfaridi 2 2,775 Sep-14-2022, 11:07 AM
Last Post: mfaridi
Question Deploy Flask apps on Windows... SpongeB0B 2 5,650 Aug-08-2021, 09:12 AM
Last Post: ndc85430
  python 3.7 on windows using flask and flask-sqlalchemy. Alpy 2 4,914 Aug-12-2020, 07:24 PM
Last Post: Alpy
  Flask - IIS Get Windows User Name beachdogvet 0 6,041 Feb-28-2020, 12:37 PM
Last Post: beachdogvet
  Flask Streaming not working on IIS Windows Revencu 0 3,144 Nov-09-2019, 10:31 PM
Last Post: Revencu
  Failing to install Flask on Windows using pip shayon 1 3,676 Jul-11-2018, 12:36 AM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020