Answer the question
In order to leave comments, you need to log in
Why doesn't a port open when I raise a service with docker-compose?
Hello, I need help.
I'm trying to deploy a 3-container system using docker-compose.
Containers:
# cat docker-compose.yml
version: "2"
services:
nodejs:
image: nodejs
ports:
- "80:44343"
links:
- c
- redis
c:
image: c
redis:
image: redis
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a6b573d13236 nodejs "npm start" 7 minutes ago Up 7 minutes 17117/tcp, 0.0.0.0:80->44343/tcp p_nodejs_1
c572e763618f c "/bin/sh -c ./src/..." 7 minutes ago Up 7 minutes 19833/tcp p_c_1
4b085da7750c redis "docker-entrypoint..." 7 minutes ago Up 7 minutes 6379/tcp p_redis_1
# docker -v
Docker version 17.09.0-ce, build afdb6d4
# docker-compose -v
docker-compose version 1.16.1, build 6d1ac219
# nmap 0.0.0.0 -p 19833
Starting Nmap 6.40 ( http://nmap.org ) at 2017-11-06 17:12 MSK
Nmap scan report for 0.0.0.0
Host is up (680s latency).
PORT STATE SERVICE
19833/tcp open unknown
Nmap done: 1 IP address (1 host up) scanned in 0.06 seconds
# docker exec -it p_nodejs_1 bash
# nmap c -p 19833
Starting Nmap 7.01 ( https://nmap.org ) at 2017-11-06 14:15 UTC
Nmap scan report for c (172.18.0.3)
Host is up (0.000046s latency).
rDNS record for 172.18.0.3: pool_c_1.pool_default
PORT STATE SERVICE
19833/tcp closed unknown
MAC Address: 02:42:AC:12:00:03 (Unknown)
Nmap done: 1 IP address (1 host up) scanned in 0.48 seconds
# nmap redis -p 6379
Starting Nmap 7.01 ( https://nmap.org ) at 2017-11-06 14:21 UTC
Nmap scan report for redis (172.18.0.2)
Host is up (0.000094s latency).
rDNS record for 172.18.0.2: pool_redis_1.pool_default
PORT STATE SERVICE
6379/tcp open unknown
MAC Address: 02:42:AC:12:00:02 (Unknown)
Nmap done: 1 IP address (1 host up) scanned in 0.48 seconds
[
{
"Name": "p_default",
"Id": "ec82da66485580f74c8897ad40db613b7997f8fd0ccf18fd0d025861fc3d96c4",
"Created": "2017-11-06T17:41:07.187705953+03:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.18.0.0/16",
"Gateway": "172.18.0.1"
}
]
},
"Internal": false,
"Attachable": true,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"1f7c97272f8c8d0635fe66714f9359f27f6eb24a1a3372162e18956c1a874542": {
"Name": "pool_redis_1",
"EndpointID": "6c565c1b720671c8cca12c32e357127de5acffbaf30c9fc3e7dea75040b62d45",
"MacAddress": "02:42:ac:12:00:02",
"IPv4Address": "172.18.0.2/16",
"IPv6Address": ""
},
"6c5dadbdd2b56935cd2dc4206d2d16a430ca336c2bfed7437e18cc6ac2ae9384": {
"Name": "pool_c_1",
"EndpointID": "36fe780b504b79d0e4013de82276ca91b744204e613e6f2c168e02d16989e0e6",
"MacAddress": "02:42:ac:12:00:03",
"IPv4Address": "172.18.0.3/16",
"IPv6Address": ""
},
"d45c570bde8a9b99fe4f3ef75d47ff9cee5cc1cbb654567714436d602c8cdbd8": {
"Name": "pool_nodejs_1",
"EndpointID": "ac55025cfa9189c0f2d6e247f3ea7c3aec668e4665c1490a65f2473240566ca8",
"MacAddress": "02:42:ac:12:00:04",
"IPv4Address": "172.18.0.4/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {
"com.docker.compose.network": "default",
"com.docker.compose.project": "p"
}
}
]
Answer the question
In order to leave comments, you need to log in
It turned out that I myself was a dunce and the docker had nothing to do with it. The bottom line is this:
a service was started in container "c" that listened on port 19833, but only with ip 127.0.0.1. Accordingly, it is impossible to connect from any other machine. Since it was not possible to force the application to listen from the 0.0.0.0 address, I solved the problem with a crutch. Installed the redir package and through it configured traffic redirection from the external port to the internal 127.0.0.1
You need to tweak docker-compose.yml a bit
version: '3.1'
services:
nodejs:
image: nodejs
ports:
- "44343:44343"
- "17117:17117"
depends_on:
-c
- redis
links:
- c:custom_app
- redis:redis
c:
image: c
ports:
- "19833:19833"
redis:
image: redis
custom_app
and redis
to connect to the appropriate containers.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question