无法从外部访问Docker容器中的应用程序

时间:2015-08-27 16:16:03

标签: docker sbt port akka-http

docker pull kovacshuni/riptube:1.0.0-SNAPSHOT
docker run -it -P --name="riptube" kovacshuni/riptube:1.0.0-SNAPSHOT
bin/riptube &
curl -X POST -d "Hi there" localhost:8082/notify
INFO 15:55:06 c.h.r.NotificationReceiver$ - Hi there

所以这很有用。但是从外面,来自docker daemon的东道主,它并没有。尽管有EXPOSE命令和-P参数。

docker port riptube 8082
0.0.0.0:32785
curl -X POST -d "Hi there" localhost:32785/notify
curl: (52) Empty reply from server

为什么呢? :( :(

源代码here。 Dockerfile也是如此,但是粘贴在下面:

 FROM frolvlad/alpine-oraclejdk8

 RUN apk add --update bash py-pip ca-certificates curl
 RUN rm -rf /var/cache/apk/*
 RUN pip install youtube-dl

 WORKDIR /opt/riptube
 ADD target/pack/ /opt/riptube
 EXPOSE 8082
 ENTRYPOINT /bin/bash
 CMD

2 个答案:

答案 0 :(得分:5)

我遇到了同样的问题:

替换这个:

private val httpBindingF = Http().bindAndHandle(ripController.route, "localhost", 8080)

用这个:

private val httpBindingF = Http().bindAndHandle(ripController.route, "0.0.0.0", 8080)

令人惊讶的是,它对我有用!

答案 1 :(得分:0)

假设您不在Linux计算机上,我猜您必须在vm中转发您的端口:

$ VBoxManage controlvm "name-of-your-vm" natpf1 "tcp-port8082,tcp,,8082,,8082"