Back to Dagger

Expose Service To Host

docs/current_docs/partials/cookbook/services/_expose-service-to-host.mdx

0.20.71.9 KB
Original Source

Expose services in Dagger Functions to the host

The Dagger Function below creates and returns an HTTP service. This service can be used from the host.

<Tabs groupId="language" queryString="sdk"> <TabItem value="go" label="Go">
go
</TabItem> <TabItem value="python" label="Python">
python
</TabItem> <TabItem value="typescript" label="TypeScript">
typescript
</TabItem> <TabItem value="php" label="PHP">
php
</TabItem> </Tabs>

Examples

  • Expose the HTTP service instantiated by a Dagger Function to the host on the default port:
<Tabs groupId="shell"> <TabItem value="System shell"> ```shell dagger -c 'http-service | up' ``` </TabItem> <TabItem value="Dagger Shell"> ```shell title="First type 'dagger' for interactive mode." http-service | up ``` </TabItem> <TabItem value="Dagger CLI"> ```shell dagger call http-service up ``` </TabItem> </Tabs>

Access the service from the host:

shell
curl localhost:8080
  • Expose the HTTP service instantiated by a Dagger Function to the host on a different host port:
<Tabs groupId="shell"> <TabItem value="System shell"> ```shell dagger -c 'http-service | up --ports 9000:8080' ``` </TabItem> <TabItem value="Dagger Shell"> ```shell title="First type 'dagger' for interactive mode." http-service | up --ports 9000:8080 ``` </TabItem> <TabItem value="Dagger CLI"> ```shell dagger call http-service up --ports 9000:8080 ``` </TabItem> </Tabs>

Access the service from the host:

shell
curl localhost:9000