Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.1k 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...