简体   繁体   中英

(gcloud.run.deploy) The user-provided container failed to start and listen

I am receiving the following error when executing gcloud run deploy --image gcr.io/my-project/my-app --platform managed --port 8080 :

ERROR: (gcloud.run.deploy) The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable. Logs for this revision might contain more information.

I have tried this with and without the port specification.

My app is written in Swift 5.7 and my dockerfile looks like this:

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"]

The app does not much so far, and has a single file:

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()
    }
}

When I build and run the container interactively locally, it works fine.

What are my options? Is there a health check going on? Can this be disabled? If not, do I need to write code just for this purpose? The error occurs immediately the image is deployed.

Cloud Run Services are meant for running web services, not arbitrary long running containers. The container contract requires that the container start a server listening on the specified port.

The other option Cloud Run supports is jobs, which expects a container that starts automatically, does some work, and exits when it's finished.

If your workload doesn't follow one of those two patterns, Cloud Run might not be the right product to use.

You can read the Cloud Run container contract in more detail here: https://cloud.google.com/run/docs/container-contract#port

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM