forked from dagger/dagger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cookbook: integrating with a docker engine (dagger#5421)
Cookbook: integrating with a Docker engine Signed-off-by: Solomon Hykes <solomon@dagger.io> Signed-off-by: Helder Correia <helder@dagger.io>
- Loading branch information
Showing
4 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
docs/current/cookbook/snippets/docker-engine-host/index.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { connect } from "@dagger.io/dagger" | ||
|
||
// create Dagger client | ||
connect( | ||
async (client) => { | ||
// setup container with docker socket | ||
const ctr = client | ||
.container() | ||
.from("docker") | ||
.withUnixSocket( | ||
"/var/run/docker.sock", | ||
client.host().unix_socket("/var/run/docker.sock") | ||
) | ||
.withExec(["docker", "run", "--rm", "alpine", "uname", "-a"]) | ||
.stdout() | ||
|
||
// print docker run | ||
console.log(await ctr.stdout()) | ||
}, | ||
{ LogOutput: process.stderr } | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"os" | ||
|
||
"dagger.io/dagger" | ||
) | ||
|
||
func main() { | ||
// create Dagger client | ||
ctx := context.Background() | ||
client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stderr)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer client.Close() | ||
|
||
// setup container with docker socket | ||
ctr := client. | ||
Container(). | ||
From("docker"). | ||
WithUnixSocket("/var/run/docker.sock", client.Host().UnixSocket("/var/run/docker.sock")). | ||
WithExec([]string{"docker", "run", "--rm", "alpine", "uname", "-a"}) | ||
|
||
// print docker run | ||
out, err := ctr.Stdout(ctx) | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Println(out) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import sys | ||
|
||
import anyio | ||
|
||
import dagger | ||
|
||
|
||
async def main(): | ||
# create Dagger client | ||
async with dagger.Connection(dagger.Config(log_output=sys.stderr)) as client: | ||
# setup container with docker socket | ||
ctr = ( | ||
client.container() | ||
.from_("docker") | ||
.with_unix_socket( | ||
"/var/run/docker.sock", | ||
client.host().unix_socket("/var/run/docker.sock"), | ||
) | ||
.with_exec(["docker", "run", "--rm", "alpine", "uname", "-a"]) | ||
) | ||
|
||
# print docker run | ||
print(await ctr.stdout()) | ||
|
||
|
||
anyio.run(main) |