Warm tip: This article is reproduced from stackoverflow.com, please click
docker couchdb

how to interpret the port information for docker containers

发布于 2020-03-27 15:47:21

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.

Questioner
dot
Viewed
112
Nguyen Lam Phuc 2020-01-31 17:19

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.