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?
CodePudding user response:
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