+-

docker-compose.yml中端口和公开选项之间的区别是什么
最佳答案
根据 docker-compose reference,
Ports定义为:
Expose ports. Either specify both ports (HOST:CONTAINER), or just the container port (a random host port will be chosen).
> docker-compose.yml中提到的端口将在docker-compose启动的不同服务之间共享.
>端口将暴露给主机到随机端口或给定端口.
我的docker-compose.yml看起来像:
mysql:
image: mysql:5.7
ports:
- "3306"
如果我做docker-compose ps,它看起来像:
Name Command State Ports
-------------------------------------------------------------------------------------
mysql_1 docker-entrypoint.sh mysqld Up 0.0.0.0:32769->3306/tcp
Expose定义为:
Expose ports without publishing them to the host machine – they’ll only be accessible to linked services. Only the internal port can be specified.
端口不会暴露给主机,只会暴露给其他服务.
mysql:
image: mysql:5.7
expose:
- "3306"
如果我做docker-compose ps,它看起来像:
Name Command State Ports
---------------------------------------------------------------
mysql_1 docker-entrypoint.sh mysqld Up 3306/tcp
点击查看更多相关文章
转载注明原文:docker-compose端口与expose之间有什么区别 - 乐贴网