T
T
tuslo2016-06-09 01:38:57
Network administration
tuslo, 2016-06-09 01:38:57

Why doesn't Docker map ports other than 80?

Hello ,
for Docker version 1.9.0, build 76d6bc9
on Ubuntu 14.04.3 LTS
, there is this docker-compose.yml:

dc1:    
    image: php
    ports:
        - "8081:8081"
    expose:
        - "8081"
dc2:    
    image: php
    ports:
        - "8082:8082"
    expose:
        - "8082"

docker ps -a gives:
80/tcp, 0.0.0.0:8081->8081/tcp   dс_1
80/tcp, 0.0.0.0:8082->8082/tcp   dс_2

But when trying to connect:
docker inspect -f "{{.NetworkSettings.IPAddress}}" dc_1 -> 172.17.0.4
curl 172.17.0.4:8081 -> curl: (7) Failed to connect to 172.17.0.4 port 8081: Connection refused

docker inspect -f "{{.NetworkSettings.IPAddress}}" dc_2 -> 172.17.0.5
curl 172.17.0.5:8082 -> curl: (7) Failed to connect to 172.17.0.5 port 8082: Connection refused

curl 172.17.0.4:80 -> OK

In option:
dc1:    
    image: php
    ports:
        - "8081:80"

the result is the same.
CHADNT? Why does the port map strictly to 80 but not to 8081/8082?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
GDApsy, 2016-06-26
@GDApsy

Perhaps this is the case:
ports:
- "8082:8082"
expose:
- "8082"
You open the same ports both outside the docker networks and inside the docker network for containers, and therefore it turns out that docker cannot simultaneously provide a port for both the outside world and internal networks.

M
Marina Mukhina, 2016-06-09
@marimysh

You can also try to run the container something like: docker run -tid -p 8081:8081 dc1
So at least it should work. Why it does not work through compose, alas, I will not say. It may only work when the servers are running together

T
tuslo, 2016-10-09
@tuslo

It should have been something like this:

dc1:    
    image: php
    ports:
        - "8081:80"   
dc2:    
    image: php
    ports:
        - "8082:80"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question