I use docker
and docker-compose
to deploy and run my java application running on port 5555.
I run it as 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. If run it inside the server everything is fine.
So these things are checked:
$: docker-compose ps
$: ufw status
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
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
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
From the docker logs of my container I found that application binds correctly to desired port:
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
From my home computer I run telnet command telnet myhost 5555
and I get an error:
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).
Else I want to point that if I telnet another container with potgresql inside it - everything is ok.
Well, shot answer is think what host you are binding.
In my case netty server was bound like this:
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!