#Exec command in a container built from my own Dockerfile

1 messages · Page 1 of 1 (latest)

waxen stump
#

HI! I'm experimenting Dagger by creating a PHP Client (using the GraphQL API).
I'm wondering how to exec a command in a container built from my own Dockerfile, not from a image pulled from the registry.

GraphQL query

// …
$query = (new Query('container'))->setSelectionSet([
        (new Query('from'))
            ->setArguments(['address' => 'my_own_php_container'])
            ->setSelectionSet([
                (new Query('withExec'))
                    ->setArguments(['args' => ['php', '-v']])
                    ->setSelectionSet([
                        'stdout'
                    ]),
            ]),
    ]);
// …

It results in

dagger run php src/client.php --debug
Error: buildkit failed to respond
Error: failed to start engine session bin: EOF: Error: buildkit failed to respond

Please visit https://dagger.io/help#go for troubleshooting guidance.

Thanks for your help

wise imp
#

Hi ! I'm doing the same but with java, so currently I will not be able to help you.
I'm just here to share api reference playground released yesterday, in case you haven't seen it. 😄
https://docs.dagger.io/api/reference/

waxen stump
#

I'm figuring out, that Dagger is always trying to pull an image from docker registry :/

(error was due to my buildkit config, it was disabled)

#

I saw the API reference, but there is no example with usage of a local image instead pulling one from the registry

#

build

frigid moon
#

Hi @waxen stump,
You're 100%right, you need to:

  1. mount your workdir inside a container, and retrieve its id: https://play.dagger.cloud/playground/WzlQY7TI5DS. You store it as a var in your file.
  2. Use that ID as a context for the build (and optionally, the name of your Dockerfile)
waxen stump
#

your link gives me a 404 page :/

frigid moon
#

Currently writing the second one 😇 (you'll have to do it as you said, with dagger run.

#

Second one -> https://play.dagger.cloud/playground/dacUIKP5xMp. It shall build the image from the Dockerfile and retrieve its id.

Then, whenever you want to execute a command inside this builded image, you use the retrieve id as the id param of the container command

#

Or an easier way is to rely on git. You pass the git id (there's an example in the references), as the context of the build, then use the id of the builded container for your future exec

#

Don't hesitate to tell me if I'm not clear 😇🙏

waxen stump
#

Thanks for your examples, I'll let you know soon 😉

waxen stump
#

I try to generate PHP object from the GraphQL Schema, but the generated code looks unsable :/
I use https://github.com/mghoneimy/php-graphql-oqm

The resulted code is valid PHP, but when I use those objects to create a GraphQL query, I catch many schema errors such as "Cannot query field "build" on type "Query"."

Is the GraphQL schema exposed on the API is rock solid?

GitHub

A PHP library which generates query object classes from API schema declaration and uses these objects to interact with GraphQL servers in a simple and intuitive way. - GitHub - mghoneimy/php-graphq...

frigid moon
waxen stump
#

Ok so the php object generator seems broken ^^

lime rune
#

Did you inspect your GraphQL query before sending it to the dagger engine?