#[SOLVED] Cannot run Postgres as a service

1 messages · Page 1 of 1 (latest)

austere creek
#

Hey guys! So, I'm trying to run Postgres as a service, which is meant to be bind to a Rust container. I'm using the following code:

// test job
func Test(ctx context.Context, env map[string]string) error {
    ...

    // setup postgres service
    postgres := client.Container().From("postgres:16").
        WithEnvVariable("POSTGRES_PASSWORD", "test").
        WithExec([]string{"postgres"}).
        WithExposedPort(5432).
        AsService(dagger.ContainerAsServiceOpts{UseEntrypoint: true})

    // setup test container
    test := client.Container().From("rust:slim").
        WithServiceBinding("postgres", postgres).
        WithEnvVariable("CARGO_TERM_COLOR", env["CARGO_TERM_COLOR"]).
        WithEnvVariable("SQLX_VERSION", env["SQLX_VERSION"]).
        WithEnvVariable("SQLX_FEATURES", env["SQLX_FEATURES"]).
        WithEnvVariable("DB_HOST", "postgres").
        WithEnvVariable("POSTGRES_USER", "postgres").
        WithEnvVariable("POSTGRES_PASSWORD", "test").
        WithEnvVariable("POSTGRES_DB", "postgres").
        WithDirectory("/hello-rust", client.Host().Directory("."))

    ...
}

When I run the pipeline, I get the following error:

Error logs:

✘ .withExec(args: ["postgres"]): Container! 0.8s
"root" execution of the PostgreSQL server is not permitted.
The server must be started under an unprivileged user ID to prevent 
possible system security compromise.

I'm using Dagger 0.15.1. Do you know what is the issue here?

lavish cliff
#

Hi @austere creek , I'm not sure you need the WithExec on the postgres container, but let me double check.

#

Just confirmed, removing the WithExec on the postgres container is exposing the service using that example. Can you try removing that line and see if it works?

austere creek
#

thank you for the help! I just did, fixed the issue, thanks for help. I was looking into an old example of this and WithExec was being used there, don’t know why

lavish cliff
austere creek
#

no no, I just came across the old dagger example repo, which is on public archive. I just couldn’t find anything relevant on the documentation for my use case. on the cookbook section there’s a mysql example which uses WithExec, but that’s a completely different scenario

#

but I think it would be relevant to add this kind of example to the cookbook, if agreed

austere creek
#

[SOLVED] Cannot run Postgres as a service

clear edge
#

I had the same exact problem. With older versions of Dagger (I am pretty sure 0.14 too), you should do WithExec().AsService(), actually you have to move any command and opts in WithExec into the dagger.ContainerAsServiceOpts() struct passed to the AsService method.
I spent hours to fix this issue after upgrading to latest version.

analog tiger
austere creek
#

lovely, thank you both for your feedback!

woeful marten
#

@clear edge @austere creek What would have been the best way to ensure you got the the right info on Services? Upgraded cleanly? Etc?