Reputation: 2513
I'm following these instructions to containerize a simple Rest API using Python Flask. https://bpostance.github.io/posts/docker-fask-api/
This command works:
docker build -t demo/flask-api:0.0 .
I can see new images with
docker images
However there seems to be problem with this: (no errors)
docker run --name demo-flask-api -d -p 5000:5000 demo/flask-api:0.0
I don't see new images with (no errors)
docker ps
And I can not open http://localhost:5000/
or http://localhost:5000/api?value=2
Upvotes: 0
Views: 153
Reputation: 20195
When we build the image and start it with an interactive shell:
cd deng.learn/docker/conda-flask-api
docker build -t test .
docker run --rm -it --entrypoint /bin/bash test
We can inspect the container. A ls
in the container shows that everything looks fine:
(base) root@df3506215bdb:/home/flask-api# ls
app environment.yml serve.sh
But when we try to run the serve.sh
script within the container, we see this:
(base) root@df3506215bdb:/home/flask-api# ./serve.sh
bash: ./serve.sh: /bin/bash^M: bad interpreter: No such file or directory
This indicates a problem with the line endings. The file serve.sh
contains windows line endings (\r\n
), which the shell does not understand properly. When we replace the windows line endings in this file with linux line endings (\n
), rebuilt the container, and start it:
docker build -t test . && docker run --rm -d -p 5000:5000 test
then a subsequent docker ps
will show the container up and running:
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3179071939ec test "./serve.sh" 36 seconds ago Up 37 seconds 0.0.0.0:5000->5000/tcp elastic_lalande
And the application is accessible through http://localhost:5000
.
Upvotes: 1