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
docker-compose.yml
app_local_new.py
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" |
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 |
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) |