加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

docker – $POSTGRES_PORT_5432_TCP_ADDR和$POSTGRES_PORT_543

发布时间:2020-12-16 03:28:44 所属栏目:安全 来源:网络整理
导读:我正在按照https://registry.hub.docker.com/_/postgres/的官方postgres图像尝试docker postgres. 在文档中,它运行以下命令并使其工作: docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgresdocker run -it --link some-pos

我正在按照https://registry.hub.docker.com/_/postgres/的官方postgres图像尝试docker postgres.

在文档中,它运行以下命令并使其工作:

docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
docker run -it --link some-postgres:postgres --rm postgres sh -c 'exec psql -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U postgres'

所以我的问题是$POSTGRES_PORT_5432_TCP_PORT和$POSTGRES_PORT_5432_TCP_ADDR来自哪里?

最佳答案
它们可通过Docker链接机制启动到第二个容器.

从https://docs.docker.com/userguide/dockerlinks/#environment-variables开始:

When two containers are linked,Docker will set some environment
variables in the target container to enable programmatic discovery of
information related to the source container.

The pattern followed is:

  • PORT__ADDR will contain just the IP address from the URL (e.g. WEBDB_PORT_8080_TCP_ADDR=172.17.0.82).
  • PORT__PORT will contain just the port number from the URL (e.g. WEBDB_PORT_8080_TCP_PORT=8080).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读