简体   繁体   中英

How do I publish a port at run time of a Docker image on Amazon Ec2?

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM