0

I am trying to build the hello word docker image. But I am not able to get any response from POSTMAN GET request. Could you pls help to resolve?

Steps Tried:

  1. My hello word program:

enter image description here

2.My docker file:

enter image description here

  1. my folder structure enter image description here

4.Building image:

enter image description here

5.Checking image: enter image description here

6.Checking docker machine ip:

enter image description here

  1. Create and run the container with docker machine ip

enter image description here

enter image description here

  1. Checking logs:

enter image description here

  1. Query with post man both local host and docker machine ip. ( No response)

Note: Tried with all options text,JSON,HTML

enter image description here

enter image description here

After that I have deleted the container & Tried to create and run with local host ip as below. Still no response from POSTMAN ( docker machine ip & local host ip)

enter image description here

enter image description here enter image description here

As Ewong suggested & other form suggested I have modified the code as below.

FROM python

WORKDIR /program

COPY requirements.txt .

RUN pip3 install -r requirements.txt

copy src/ .

EXPOSE 5000

CMD [ "python","./app.py","--host", "0.0.0.0" ]


from flask import Flask

app = Flask(__name__)

@app.route("/")
def home():
    return "Hello world"


if __name__ == "__main__":
    app.run()

But when i give curl command failed:

enter image description here

thangaraj1980
  • 141
  • 2
  • 11
  • Please include your code and output as Text and not as images. – ewokx Apr 14 '22 at 03:08
  • While you're exposing the port 5000, you're not going to be able to access that system when you have the system listening at ```127.0.0.1:5000``` – ewokx Apr 14 '22 at 03:10

1 Answers1

0

Your docker image app is listening on 127.0.0.1:5000. It's going to ignore everything coming in from the external IP.

Change:

    app.run(debug=True, host="127.0.0.1", port=5000)

to:

    app.run(debug=True, host="0.0.0.0", port=5000)
ewokx
  • 2,204
  • 3
  • 14
  • 27
  • Hi Ewong,I have update the app.py as you mentioned. How should run the docker? I have used both option to run e.g docker run -p 127.0.0.1:5000:5000 api_testing and docker run -p 0.0.0.0:5000:5000 still i am not able to get POST response. – thangaraj1980 Apr 14 '22 at 05:13
  • You run it the same way. – ewokx Apr 14 '22 at 05:15