手动停止或启动 Azure 容器实例中的容器Manually stop or start containers in Azure Container Instances

容器组的重启策略设置确定默认情况下容器实例如何启动或停止。The restart policy setting of a container group determines how container instances start or stop by default. 可以通过手动停止或启动容器组来替代默认设置。You can override the default setting by manually stopping or starting a container group.

停止Stop

通过特定方式(例如,使用 az container stop 命令或 Azure 门户)手动停止正在运行的容器组。Manually stop a running container group - for example, by using the az container stop command or Azure portal. 对于某些容器工作负载,可能需要在规定的一段时间后停止长时间运行的容器组,以便节省成本。For certain container workloads, you might want to stop a long-running container group after a defined period to save on costs.

容器组进入“已停止”状态时,会终止并回收组中的所有容器。 它不保留容器状态。When a container group enters the Stopped state, it terminates and recycles all the containers in the group. It does not preserve container state.

回收容器后,会解除分配资源,并停止容器组的计费。When the containers are recycled, the resources are deallocated and billing stops for the container group.

如果容器组已终止(处于“成功”或“失败”状态),则停止操作无效。The stop action has no effect if the container group already terminated (is in either a Succeeded or Failed state). 例如,其一次性运行的容器任务已成功运行的容器组会以“成功”状态终止。For example, a container group with run-once container tasks that ran successfully terminates in the Succeeded state. 尝试停止处于该状态的组不会更改状态。Attempts to stop the group in that state do not change the state.

开始Start

当容器组停止时(因为容器自行终止或者你手动停止了组),你可以启动容器。When a container group is stopped - either because the containers terminated on their own or you manually stopped the group - you can start the containers. 例如,使用 az container start 命令或 Azure 门户手动启动组中的容器。For example, use the az container start command or Azure portal to manually start the containers in the group. 如果更新了任何容器的容器映像,则会拉取一个新映像。If the container image for any container is updated, a new image is pulled.

启动容器组会使用相同的容器配置开始一个新部署。Starting a container group begins a new deployment with the same container configuration. 此操作可帮助你快速重复使用按预期方式工作的已知容器组配置。This action can help you quickly reuse a known container group configuration that works as you expect. 你无需创建新的容器组便可运行相同的工作负荷。You don't have to create a new container group to run the same workload.

容器组中的所有容器都通过此操作启动。All containers in a container group are started by this action. 无法启动组中的特定容器。You can't start a specific container in the group.

手动启动或重启容器组后,容器组将根据所配置的重启策略运行。After you manually start or restart a container group, the container group runs according to the configured restart policy.

重新启动Restart

可以通过特定方式(例如,使用 az container restart 命令)在容器组正在运行时将其重启。You can restart a container group while it is running - for example, by using the az container restart command. 此操作会重启容器组中的所有容器。This action restarts all containers in the container group. 如果更新了任何容器的容器映像,则会拉取一个新映像。If the container image for any container is updated, a new image is pulled.

如果你想要排查部署问题,则重启容器组会有所帮助。Restarting a container group is helpful when you want to troubleshoot a deployment problem. 例如,如果临时资源限制阻止了你的容器成功运行,则重启组可能会解决此问题。For example, if a temporary resource limitation prevents your containers from running successfully, restarting the group might solve the problem.

容器组中的所有容器都通过此操作重启。All containers in a container group are restarted by this action. 无法重启组中的特定容器。You can't restart a specific container in the group.

手动重启容器组后,容器组会根据所配置的重启策略运行。After you manually restart a container group, the container group runs according to the configured restart policy.

后续步骤Next steps

详细了解 Azure 容器实例中的重启策略设置Learn more about restart policy settings in Azure Container Instances.

除了使用现有配置手动停止和启动容器组外,还可以对正在运行的容器组执行更新设置操作。In addition to manually stopping and starting a container group with the existing configuration, you can update the settings of a running container group.