[英]Docker container unreachable from remote machine
I use docker
and docker-compose
to deploy and run my java application running on port 5555. 我使用
docker
和docker-compose
部署并运行在端口5555上运行的Java应用程序。
I run it as docker-compose -f docker-compose.yml up -d
我将其作为
docker-compose -f docker-compose.yml up -d
But if I run telnet command outside of my server where docker container is runnig I get Connection refused
message. 但是,如果我在运行docker容器的服务器外部运行telnet命令,则会收到
Connection refused
消息。 If run it inside the server everything is fine. 如果在服务器内部运行它,一切都很好。
So these things are checked: 所以检查了这些事情:
$: docker-compose ps $:docker-compose ps
$: ufw status $:ufw状态
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
5555/tcp ALLOW Anywhere
5432 ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
5555/tcp (v6) ALLOW Anywhere (v6)
5432 (v6) ALLOW Anywhere (v6)
docker-compose.yml 泊坞窗,compose.yml
version: '3'
services:
db:
container_name: db
image: postgres
restart: always
ports:
- 5432:5432
auth:
container_name: auth
image: registryimg
restart: always
stdin_open: true
tty: true
ports:
- 5555:5555
Dockerfile Dockerfile
FROM openjdk:8-jre
ADD target/auth.jar app.jar
EXPOSE 5555
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "app.jar"]
Update 1 更新1
From the docker logs of my container I found that application binds correctly to desired port: 从我容器的docker日志中,我发现应用程序正确绑定到所需的端口:
2019-01-18 10:18:11.481 DEBUG 1 --- [ntLoopGroup-2-1] io.netty.handler.logging.LoggingHandler : [id: 0xaf27337e] REGISTERED
2019-01-18 10:18:11.485 DEBUG 1 --- [ntLoopGroup-2-1] io.netty.handler.logging.LoggingHandler : [id: 0xaf27337e] BIND: localhost/127.0.0.1:5555
2019-01-18 10:18:11.489 DEBUG 1 --- [ntLoopGroup-2-1] io.netty.handler.logging.LoggingHandler : [id: 0xaf27337e, L:/127.0.0.1:5555] ACTIVE
Update 2 更新2
From my home computer I run telnet command telnet myhost 5555
and I get an error: 在我的家用计算机上,我运行telnet命令
telnet myhost 5555
,但出现错误:
Trying myhost...
telnet: Unable to connect to remote host: Connection refused
After it's done I watch my container logs and they are empty (netty didn't register any connections). 完成之后,我查看了我的容器日志,它们是空的(netty没有注册任何连接)。
Else I want to point that if I telnet another container with potgresql inside it - everything is ok. 否则,我想指出的是,如果我通过telnet在其中包含potgresql的另一个容器中-一切正常。
Well, shot answer is think what host you are binding . 好吧,简单的答案就是考虑您要绑定的主机 。
In my case netty server was bound like this: 在我的情况下,netty服务器是这样绑定的:
BIND: localhost/127.0.0.1:5555
I've change it to: 我将其更改为:
BIND: 0.0.0.0/0.0.0.0:5555
And it works like a charm! 它就像一个魅力!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.