Open StefanoSega opened 4 years ago
in details, my Dockerfile looks like:
FROM python:2.7
COPY ./requirements.txt /app/
RUN pip install -r /app/requirements.txt
COPY . /app
WORKDIR /app
EXPOSE 4242
CMD cd /app/scripts && python -m pico.server app
... to run app.py
in /app/scripts
.
Pico Server seems running correctly:
docker build -t test-app -f Dockerfile .
docker run -p 4242:4242 test-app
INFO:werkzeug: * Running on http://127.0.0.1:4242/ (Press CTRL+C to quit)
INFO:werkzeug: * Restarting with stat
WARNING:werkzeug: * Debugger is active!
INFO:werkzeug: * Debugger PIN: 291-906-790
but trying to hit any endpoint with whatever REST method it always end up not getting any response, and nothing logged on console
Hi, your issue is because the pico server defaults to running on localhost (127.0.0.1) which is internal to the docker container. You need it to run on 0.0.0.0
to be able to access it from outside the container.
There is not a ip option for the pico.server
command so normally you would have to write your own server script based on pico/server.py
where you change the ip. Something like this called server.py
:
import pico.server
import example
pico.server.run_app(example.app, ip='0.0.0.0', port=4242)
There is however an open PR from just a few days ago which adds this option: #21
@fergalwalsh thanks a lot!
Just for anyone that will read this post, my solution in the Dockerfile looks like:
FROM python:2.7
COPY ./requirements.txt /app/
RUN pip install -r /app/requirements.txt
# todo: PLEASE REMOVE ONCE PR https://github.com/fergalwalsh/pico/pull/21 WILL BE MERGED!
# We'll need to update Pico to the new version at that time
RUN pip install werkzeug==0.16.1
RUN pip install git+https://github.com/rbeneyt/pico.git@73937f0af17496629d0afdf73391a3b80854a9ff
COPY . /app
WORKDIR /app
EXPOSE 4242
CMD cd /app/scripts/python_scripts && python -m pico.server ml_server 0.0.0.0
@fergalwalsh I'm running a pico server with the command
python -m pico.server app
: everything works fine locally or in a EC2 instance, but running it inside a Docker container with docker-composite is not reachable despite opening the port 4242