dot
dot

Reputation: 15660

how to interpret the port information for docker containers

I just used a sample docker compose yml file to create some containers and I ended up with this:

PS C:\Users\jj> docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                                                  NAMES
70ef2ac09df0        couchdb:latest      "tini -- /docker-ent…"   9 seconds ago       Up 6 seconds        4369/tcp, 9100/tcp, 0.0.0.0:25984->5984/tcp, 0.0.0.0:25986->5986/tcp   jj_server-2_1
4ee92fc98788        couchdb:latest      "tini -- /docker-ent…"   9 seconds ago       Up 5 seconds        0.0.0.0:5984->5984/tcp, 4369/tcp, 9100/tcp, 0.0.0.0:5986->5986/tcp     jj_server-0_1
37c1a3a9be48        couchdb:latest      "tini -- /docker-ent…"   9 seconds ago       Up 5 seconds        4369/tcp, 9100/tcp, 0.0.0.0:15984->5984/tcp, 0.0.0.0:15986->5986/tcp   jj_server-1_1

Trying to understand the port information.

 4369/tcp, 9100/tcp, 0.0.0.0:15984->5984/tcp, 0.0.0.0:15986->5986/tcp   jj2_server-1_1

This is what I have in part, in the docker-compose.yml that was used:

  server-0:
    environment:
      COUCHDB_PASSWORD: -pbkdf2-847043acc65626c8eb98da6d78682fbc493a1787,f7b1a3e4b624f4f0bbfe87e96841eda0,10
      COUCHDB_SECRET: 0123456789abcdef0123456789abcdef
      COUCHDB_USER: couchdb
      NODENAME: couchdb-0
    image: couchdb:latest
    networks:
      network:
        aliases:
          - couchdb-0
    ports:
      - "5984:5984"
      - "5986:5986"
    volumes:
      - "volume-0:/opt/couchdb/data"

Full yml file can be found here: https://github.com/apache/couchdb-docker/issues/74 Only thing I changed was the name of the nodes.

In the case of this specific container... does it mean that the HOST machine's port 5984 is mapped to container's 5984? And in the case of server2, the HOST machines's port 25984 is mapped to the container's 5984?

Can someone explain some of the other ports? 4369 seems to be used for clustering in some cases... like for RabbitMQ.. but i'm not sure if that's the case here for couchDB. Same goes for 9100... not sure why that gets created. Sorry, I'm a docker noob. and a couchDB noob.

Thanks.

Upvotes: 3

Views: 1456

Answers (2)

Nguyen Lam Phuc
Nguyen Lam Phuc

Reputation: 1421

In the case of this specific container... does it mean that the HOST machine's port 5984 is mapped to container's 5984? And in the case of server2, the HOST machines's port 25984 is mapped to the container's 5984?

Yes, it means that:

  • Host machine's port 5984 will be mapped to the container jj_server-0_1's port 5984
  • Host machine's port 25984 will be mapped to the container jj_server-2_1's port 5984
  • Please note that all the ports within HOST machine as well as different containers need to be unique while different containers can expose the same port. Meaning jj_server-0_1 and jj_server-2_1 can both expose port 5984

Can someone explain some of the other ports? 4369 seems to be used for clustering in some cases... like for RabbitMQ.. but i'm not sure if that's the case here for couchDB. Same goes for 9100... not sure why that gets created. Sorry, I'm a docker noob. and a couchDB noob.

Some other ports like 4369 or 9100 are being created as a result of the command EXPOSE 5984 4369 9100 as you can find in their Dockerfile. This is just a convenient and optional way to indicate that this image/container will be listening to these ports and you can expose or link them to your host machine if needed.

Upvotes: 1

Matus Danoczi
Matus Danoczi

Reputation: 137

Yes, this feature of docker is called exposed mode, where some ports are exposed to host system so you can access them from outside of Docker. As in your example port 4369 is used only internally and is not exposed, while others 2 are exposed and can be accessed from outside.

As can be also seen, all 3 containers are exposing same internal ports to some host ports, means you can access them from outside by ports 5984,15984 and 25984, same applies for 5986, 15986, 25986.

0.0.0.0:25984->5984/tcp, 0.0.0.0:25986->5986/tcp jj_server-2_1 
0.0.0.0:5984->5984/tcp, 4369/tcp, 9100/tcp, 0.0.0.0:5986->5986/tcp     jj_server-0_1
0.0.0.0:15984->5984/tcp, 0.0.0.0:15986->5986/tcp jj_server-1_1

I am also not couch db user, so cannot tell you from experience, but here is the link to the official documentation with explanation of ports and their usage CouchDB ports

Upvotes: 1

Related Questions