【Docker】Dockerfile 最佳实践-EXPOSE
参考教程:https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
环境
- virtual box 6.1
- centos 7.8
- docker 19.03
EXPOSE
The EXPOSE
instruction indicates the ports on which a container listens for connections. Consequently, you should use the common, traditional port for your application. For example, an image containing the Apache web server would use EXPOSE 80
, while an image containing MongoDB would use EXPOSE 27017
and so on.
EXPOSE
指令指示容器侦听连接的端口。因此,您应该为应用程序使用通用的传统端口。例如,包含 Apache Web 服务器的镜像将使 EXPOSE 80
,而包含 MongoDB 的镜像将使用 EXPOSE 27017
,依此类推。
For external access, your users can execute docker run
with a flag indicating how to map the specified port to the port of their choice. For container linking, Docker provides environment variables for the path from the recipient container back to the source (ie, MYSQL_PORT_3306_TCP
).
对于外部访问,您的用户可以执行带有标志的 docker run
命令,该标志指示如何将指定端口映射到他们选择的端口。对于容器链接,Docker 为从接收者容器到源容器的路径提供了环境变量(即,MYSQL_PORT_3306_TCP
)。
总结
介绍了 Dockerfile 的 EXPOSE 指令的最佳实践。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!