如何使用YAML文件映射azure容器实例上的转发端口



Azure容器实例YAML引用提供了在容器中公开多个端口的选项。见https://learn.microsoft.com/en-us/azure/container-instances/container-instances-reference-yaml

然而,我还没有弄清楚如何映射/转发端口,就像我们用docker做的那样。我想在YAML文件上定义一个端口转发,就像我们使用docker命令一样:

docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=pw' -p 14000:1433

使用Azure YAML模式有限制吗?

I have try:

ports:
- port: 11401
- port: 1433

但是它打开了两个端口

根据文档和文档,请尝试使用format:

ports:
- "14000:1433"

根据下面的文档,Azure容器实例不支持

引用有关更多详细信息,请参阅本文档:排除常见问题- Azure容器实例| Microsoft Learn

您在容器实例中公开的端口应该是相同的

然而,你可以通过在docker文件中定义参数和环境变量来实现它,这些参数和环境变量允许你在部署期间覆盖port。

例如,默认情况下,下面的docker文件将侦听http端口80,因为http_port被设置为80。

#Dockerfile
FROM TestImage
ARG http_port=80
ENV target_port ${http_port}
.
.
.

但是如果您需要ACI监听不同的端口,那么在ACI部署yaml文件的环境变量中定义target_port,如下所示。

#Azure container instance yaml file
apiVersion: ‘2021-10-01’
location: <location-name>
name: <container instance group name>
properties:
containers:
- name: <container-name>
properties:
image: <image-name:version>
environmentVariables:
- name: target_port
value: 8090 # once this environment variable defined, the port in the image will change to 8090.
ports:
- port: 8090
protocol: tcp
ipAddress:
type: Public  #value can be Public or Private
ports:
- protocol: tcp
port: 8090
type: Public
type:Microsoft.ContainerInstance/containerGroups

一旦上面的文件已经部署,Azure容器实例开始监听端口8090,即使镜像端口是80。

最新更新