November 3, 20241 yr I'm trying to run a simple Flask app locally from a docker and I seem to be stuck... I have the following Dockerfile: FROM python:3.11-slim WORKDIR /usr/src/app RUN python -m pip install flask COPY . . EXPOSE 5000 CMD [ "flask", "run"] and a basic flask app defined in app.py: import flask app = flask.Flask(__name__) @app.route('/') def helloworld(): return 'HELLO, WORLD' I copied these two files to my Unraid server and ran `docker build -t myapp .` then `docker run -it myapp`, which yields the expected message: * Debug mode: off WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Running on http://127.0.0.1:5000 Press CTRL+C to quit Based on instructions from here, I set up a local private Docker registry `myrepo` and I then created the following `myapp.xml` file: <?xml version="1.0" encoding="utf-8"?> <Container> <Beta>False</Beta> <Category>HomeAutomation:</Category> <Date>2024-11-03</Date> <Changes> [b]3.NOV.2024:[/b]Added[br] </Changes> <Support>http://forums.unraid.net</Support> <Name>myapp</Name> <Description> myapp server </Description> <Registry>http://unraid:5000/myapp/</Registry> <GitHub>https://github.com/</GitHub> <Repository>localhost:5000/myapp</Repository> <BindTime>true</BindTime> <Privileged>false</Privileged> <Networking> <Mode>bridge</Mode> <Publish> <Port> <HostPort>3016</HostPort> <ContainerPort>5000</ContainerPort> <Protocol>tcp</Protocol> </Port> </Publish> </Networking> <WebUI>http://[IP]:[PORT:3016]</WebUI> <Banner>http://i.imgur.com/zXpacAF.png</Banner> <Icon>http://i.imgur.com/zXpacAF.png</Icon> </Container> I then copied `myapp.xml` to `/boot/config/plugins/community.applications/private/myrepo`, stop and restart Docker, and install `myapp` from Unraid Apps. Then in Docker, clicking on `myapp`'s log yields the expected message again, so at least my app is running: WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Running on http://127.0.0.1:5000 Press CTRL+C to quit * Debug mode: off In the list of Docker containers, `myapp` is listed with the following port mappings: `172.17.0.6:5000/TCP <=> 192.168.1.50:3016`. When I point my browser to http://192.168.1.50:3016/, I get an error ("Unable to connect"), and the logs don't show any activity within the container. I've tried various different settings but I seem to be stuck. Is it a matter of telling flask to run from host 172.17.0.6 instead of 127.0.0.1? I'd greatly appreciate some suggestions at this point.
November 4, 20241 yr Author Got it! It was indeed a host setting. For whoever this might help, this is what worked: CMD [ "python", "-m", "flask", "run", "-h", "0.0.0.0"] Now I'm wondering if there is a way to specify, in the myapp.xml configuration file, that container path /usr/src/app/data should be mapped to a specific host path. I was able to change this using the GUI aftr installing myapp, but how can I specify this as a default preset?
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.