-1

Currently, my Docker image runs as expected when run with the following line inside VSCode's CLI.

docker run -it -d -p 5000:5000 flaskapp 

This allows me to open up http://localhost:5000/ and access it. However, if I were to run it on Docker desktop, it does not allow me to access the localhost. Under my Dockerfile, I have made sure to include EXPOSE 5000 inside.

docker build -t flaskapp:latest .

How do I run a Docker image inside Docker desktop or EC2 with the -p flag?

Peek0
  • 173
  • 2
  • 9
  • I'm also using docker desktop, once the port is mounted to host you just can use with localhost. When the time docker not support windows and used docker tool that time only this happened – Shamith Wimukthi Aug 11 '22 at 06:01

1 Answers1

1

We need to specify host as 0.0.0.0 in the app.run().

Eg: app.run(host="0.0.0.0")

Then add an inbound rule in the ec2 instance security group to expose the port.

Use the ec2 instance IP with the port number to access it.

Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
Mathan
  • 51
  • 2