Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.8k views
in Technique[技术] by (71.8m points)

amazon web services - Call Container running on AWS EC2

I have a Linux EC2 with docker running inside of it. Docker is running 3 services. 2 are workers and one is an API.

I want to be able to call that API from outside the system but I am getting "This site can't be reached". The service is running and the call is a simple ping which works locally through VS so I don't believe that is the issue.

My security group has all traffic allowed with 0.0.0.0/0.

I have attempted the following urls but no luck:

  • http://ec2-{public-ip}.ap-southeast-2.compute.amazonaws.com/ping
  • http://{public-ip}/ping
  • http://{public-ip}/172.17.0.2/ping (containers IP address)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Based on the comments.

EXPOSE does not actually "exposes" a port:

The EXPOSE instruction does not actually publish the port. It functions as a type of documentation between the person who builds the image and the person who runs the container, about which ports are intended to be published. To actually publish the port when running the container, use the -p flag on docker run to publish and map one or more ports, or the -P flag to publish all exposed ports and map them to high-order ports.

Thus, to expose port 80 from your container to the instance you have to use -p 80:80 option.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...