swift (gcloud.run.deploy)用户提供的容器无法启动和侦听

6ju8rftf  于 2023-01-12  发布在  Swift
关注(0)|答案(1)|浏览(128)

我在执行gcloud run deploy --image gcr.io/my-project/my-app --platform managed --port 8080时收到以下错误:
错误:(gcloud.run.deploy)用户提供的容器无法启动并侦听PORT=8080环境变量提供的定义端口。此修订版本的日志可能包含详细信息。
我已经尝试过使用和不使用端口规范。
我的应用程序是用Swift 5.7编写的,dockerfile看起来像这样:

FROM swift:latest

# Copy the package source code
COPY . /MyApp
WORKDIR /MyApp

# Build the package
RUN swift build -c release --build-path /build

ENTRYPOINT ["/build/release/MyApp"]

该应用程序没有太多到目前为止,并有一个单一的文件:

import Foundation

@main
public struct MpApp {
    public private(set) var text = "Hello, World!"

    public static func main() {
        // Set up a signal handler for the SIGINT signal
        signal(SIGINT) { signal in
            print("Received SIGINT signal, executing clean-up code...")

            print("Exiting...")

            exit(0)
        }

        let runLoop = RunLoop.current

        let timer = Timer(timeInterval: 1.0, repeats: true) { timer in
            print("Running...")
        }

        runLoop.add(timer, forMode: .default)

        runLoop.run()
    }
}

当我在本地交互式地构建和运行容器时,它工作得很好。
我有什么选择?是否正在进行运行状况检查?是否可以禁用此功能?如果不能,是否需要为此编写代码?部署映像后立即发生错误。

nx7onnlm

nx7onnlm1#

Cloud Run Services用于运行Web服务,而不是任意长时间运行的容器。容器协定要求容器启动侦听指定端口的服务器。
Cloud Run支持的另一个选项是作业,它期望容器自动启动,执行一些工作,并在完成时退出。
如果您的工作负载不遵循这两种模式中的任何一种,那么Cloud Run可能不是适合使用的产品。
您可以在此处阅读Cloud Run容器合同的更多详细信息:https://cloud.google.com/run/docs/container-contract#port

相关问题