简体   繁体   中英

What is the difference between target and published ports into docker-compose.yml container definition?

I am not into Docker and I have the following doubt related the docker-compose.yml file. Suppose that this is the definition of one of the container described into this file:

pgadmin: image: dpage/pgadmin4 restart: unless-stopped container_name: pgadmin4

networks:
  ntpgsql:
    ipv4_address: 172.21.0.3
ports:
  - target: 80
    published: 80
    protocol: tcp
    mode: host
environment:
  - PGADMIN_CONFIG_SERVER_MODE=True
  - PGADMIN_DEFAULT_EMAIL=nobili.andrea@gmail.com
  - PGADMIN_DEFAULT_PASSWORD=123_Stella

Basically it set the IP address of this container to 172.21.0.3 . My doubt is related to the ports definition. It is defining the internal and external ports in this way:

- target: 80
  published: 80

What is the difference between these 2 ports? From what I have understood one is the internal and the other is the external (but what is what? and what it means?)

Publishing a port creates a port forward from the host into the container. The published port is the externally visible port on the host. The target port is the destination inside the container for this port forward. From the documentation:

  • target: the port inside the container
  • published: the publicly exposed port
  • protocol: the port protocol (tcp or udp)
  • mode: host for publishing a host port on each node, or ingress for a swarm mode port to be load balanced.

https://docs.docker.com/compose/compose-file/compose-file-v3/#ports

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM