donglin7383 2016-05-28 16:39
浏览 848
已采纳

Docker-无法从外部访问docker端口

So i created a new EC2 Instance and installed docker on it.

I deployed code from ( https://github.com/commonsearch/cosr-front/blob/master/INSTALL.md ) and followed install instructions.

Install was successfull and i started the server:

[ec2-user@ip-172-30-0-127 cosr-front]$ make docker_devserver
docker run -e DOCKER_HOST --rm -v "/home/ec2-user/cosr-front:/go/src/github.com/commonsearch/cosr-front:rw" -w /go/src/github.com/commonsearch/cosr-front -p 9700:9700 -i -t commonsearch/local-front make devserver
mkdir -p build
go build -o build/cosr-front.bin ./server
GODEBUG=gctrace=1 COSR_DEBUG=1 ./build/cosr-front.bin
2016/05/28 16:32:38 Using Docker host IP: 172.17.0.1
2016/05/28 16:32:38 Server listening on 127.0.0.1:9700 - You should open http://127.0.0.1:9700 in your browser!

Well, now when i want to access it from outside, i cant! Not even curl the local server.

When i run docker ps it gives me correct port forwarding:

[ec2-user@ip-172-30-0-127 ~]$ docker ps
CONTAINER ID        IMAGE                                       COMMAND                  CREATED             STATUS              PORTS                                              NAMES
1a9f77e1eeb1        commonsearch/local-front                    "make devserver"         4 minutes ago       Up 4 minutes        0.0.0.0:9700->9700/tcp                             stoic_hopper
9ff00fe3e70d        commonsearch/local-elasticsearch-devindex   "/docker-entrypoint.s"   4 minutes ago       Up 4 minutes        0.0.0.0:39200->9200/tcp, 0.0.0.0:39300->9300/tcp   kickass_wilson

These are my docker images:

REPOSITORY                                  TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
<none>                                      <none>              3e205118cd3f        17 minutes ago      853.3 MB
<none>                                      <none>              1d233da1fa59        2 hours ago         955.7 MB
debian                                      jessie              ce58426c830c        4 days ago          125.1 MB
commonsearch/local-front                    latest              30de7ab48d43        7 weeks ago         1.024 GB
commonsearch/local-elasticsearch-devindex   latest              b1156ada5a24        11 weeks ago        383.2 MB
commonsearch/local-elasticsearch            latest              808e72f49b4a        3 months ago        355.2 MB

I have tryed disabling ipv6 and all kind of nonsense google offered me, but without success.

Any ideas ?

EDIT:

Also, if i enter the docker container for frontend( using docker exec ), then I CAN PING AND CULR the frontend.

But i cant from the outside( nor ssh, not from my home pc using browser ).

Also my docker version:

Client:
 Version:      1.9.1
 API version:  1.21
 Go version:   go1.4.2
 Git commit:   a34a1d5/1.9.1
 Built:        
 OS/Arch:      linux/amd64

Server:
 Version:      1.9.1
 API version:  1.21
 Go version:   go1.4.2
 Git commit:   a34a1d5/1.9.1
 Built:        
 OS/Arch:      linux/amd64
  • 写回答

2条回答 默认 最新

  • dsjklb0205 2016-05-30 06:42
    关注

    I made a issue at github as swell and one guy saved the day.

    Here's he's response:

    Server listening on 127.0.0.1:9700 Your application is listening on localhost. localhost is scoped to the container itself. Thus to be able to connect to it, you would have to be inside the container. To fix, you need to get your application to listen on 0.0.0.0 instead.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条