【问题标题】:In EC2 not able to curl localhost, using wildfly swarm在 EC2 中无法使用 wildfly swarm 卷曲 localhost
【发布时间】:2018-01-07 13:25:56
【问题描述】:

我有一个 Wildfly swarm 应用程序在 Amazon EC2 的 docker 容器中运行。

这是我的 Docker ps:

913171ca1a34        xxxxxxxxxxx/myrepository:osapp2.0   "java -jar /app/Or..."   55 minutes ago      Up 55 minutes       8080/tcp, 0.0.0.0:4000->80/tcp   elastic_yonath

netstat -ano | grep 4000 gives following output
tcp        0      0 :::4000                     :::*                        LISTEN      off (0.00/0/0)

 netstat -ano | grep 80
udp        0      0 fe80::841:a6ff:fe76:c70c:546 :::*                                    off (0.00/0/0)
udp        0      0 :::53880                    :::*                                    off (0.00/0/0)
unix  3      [ ]         STREAM     CONNECTED     9800

我已经在我的 EC2 的安全组中启用了入站端口 80

我已经根据 StackOverflow 中的其他整体从 /etc/hosts 文件中删除了 ::1

我在使用 curl 时得到:

"curl http://locahost:4000"
curl: (56) Recv failure: Connection reset by peer

"curl http://localhost:8080"
curl: (56) Recv failure: Connection reset by peer

我可以在本地系统中运行我的 docker。

我做错了什么?

这是我的 IPtables:

sudo iptables -S
-P INPUT ACCEPT

-P FORWARD DROP

-P OUTPUT ACCEPT

-N DOCKER

-N DOCKER-ISOLATION

-A FORWARD -j DOCKER-ISOLATION

-A FORWARD -o docker0 -j DOCKER

-A FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT

-A FORWARD -i docker0 ! -o docker0 -j ACCEPT

-A FORWARD -i docker0 -o docker0 -j ACCEPT

-A DOCKER -d 172.17.0.2/32 ! -i docker0 -o docker0 -p tcp -m tcp --dport 80 -j ACCEPT

-A DOCKER-ISOLATION -j RETURN

我做了一个 netstat -antp,这里的端口被列为 IPV6 地址?如何使用 IPV4 配置运行我的 docker

sudo netstat -antp 活跃的互联网连接(服务器和已建立)

Proto Recv-Q Send-Q 本地地址 国外地址
状态 PID/程序名称

tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 2294/rpcbind

tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2481/sshd

tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2511/sendmail

tcp 0 0 0.0.0.0:51501 0.0.0.0:*
听 2315/rpc.statd

tcp 0 300 172.30.1.61:22 202.60.62.100:39334 ESTABLISHED 4539/sshd

tcp 0 0 :::111 :::* LISTEN 2294/rpcbind

tcp 0 0 :::22 :::* LISTEN 2481/sshd

tcp 0 0 :::36475 :::* LISTEN 2315/rpc.statd

tcp 0 0 :::4000 :::* LISTEN 4431/docker-proxy

【问题讨论】:

  • 你真的在使用http:\localhost吗?你知道是http://localhost,对吧?
  • 是的,我使用的是locahost,但在此发布之前再次收到错误消息,我使用 http:\\locahost 时犯了一个错误。我现在在我的帖子中更新了正确的错误消息。感谢您的关注。
  • serverfault.com/questions/769578/… 这与我的问题有关。我可以在我的容器内卷曲。但我不明白这里列出的解决方案。
  • docker exec -it d86aed3df80e bash 然后 curl localhost:8080/rest/orderapp?ordernumber=101&&offset=1,我可以访问我的服务了。
  • 这是上述行的 docker run 命令 docker run -d -p 8080:80 raxxxxx/myrepository:osapp3.0

标签: docker amazon-ec2 tcp port wildfly-swarm


【解决方案1】:

此链接向我展示了一种方法 "https://serverfault.com/questions/769578/curl-56-recv-failure-connection-reset-by-peer-when-hitting-docker-container"

我能够连接到 docker bash 并且能够 curl 网址

所以我做了两件事 1) 在我的 Maven POM.xml 中,我添加了一个配置来设置 0.0.0.0
要么 2) 我本可以在 docker 文件的入口点标记中传递绑定地址

然后我在 docker run 命令中使用了 8080 端口

docker run -d -p 8080:8080 rajxxxxxx/myrepository:osapp3.0

现在我可以在 EC2 中卷曲“http://localhost:8080/rest/orderapp?ordernumber=102&&offset=1

【讨论】:

    猜你喜欢
    • 2018-05-24
    • 2015-12-30
    • 2017-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-04
    • 1970-01-01
    相关资源
    最近更新 更多