知识卡片

普通读书笔记卡 · 3522.b

端口映射让主机访问容器

理解等级:中级

容器内服务监听 8000 端口后,运行时仍需把主机端口映射至容器端口,主机客户端才能经该地址访问。-p 8000:8000 承担发布端口的动作;镜像中的 EXPOSE 是声明信息,不能独自完成主机端口映射。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    原书出处

    参考来源

    - 位置:《Microservice APIs》第 13 章《Dockerizing microservice APIs》(源文件:_epub-src/OEBPS/Text/13.htm) - 结论依据:原文用 -p 将容器端口绑定到主机;EXPOSE 被描述成可访问条件,但实际映射由运行参数完成。 - 原始内容:To make the application accessible to the host machine, we use the -p flag, which allows us to bind the port on which the application is running inside the container to a port in the host machine. We also use the -v