docs/versioned_docs/version-0.16.3/features/services.mdx
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
Dagger Functions support service containers, enabling users to spin up additional services (as containers) and communicate with those services from their pipelines.
This makes it possible to:
Services instantiated by a Dagger Function run in service containers, which have the following characteristics:
Some common scenarios for using services with Dagger Functions are:
Here is an example of a Dagger Function that returns an HTTP service, which can then be accessed from the calling host:
<Tabs groupId="language"> <TabItem value="Go"> ```go file=./snippets/services-1/go/main.go ``` </TabItem> <TabItem value="Python"> ```python file=./snippets/services-1/python/main.py ``` </TabItem> <TabItem value="TypeScript"> ```typescript file=./snippets/services-1/typescript/index.ts ``` </TabItem> <TabItem value="PHP"> ```php file=./snippets/services-1/php/src/MyModule.php ``` </TabItem> <TabItem value="Java"> ```java file=./snippets/services-1/java/src/main/java/io/dagger/modules/mymodule/MyModule.java ``` </TabItem> </Tabs>See it in action:
This also works in the opposite direction: containers in Dagger Functions can communicate with services running on the host. Here's an example of how a pipeline running in a Dagger Function can access and query a MariaDB database service running on the host:
<Tabs groupId="language"> <TabItem value="Go"> ```go file=./snippets/services-2/go/main.go ``` </TabItem> <TabItem value="Python"> ```python file=./snippets/services-2/python/main.py ``` </TabItem> <TabItem value="TypeScript"> ```typescript file=./snippets/services-2/typescript/index.ts ``` </TabItem> <TabItem value="PHP"> ```php file=./snippets/services-2/php/src/MyModule.php ``` </TabItem> <TabItem value="Java"> ```java file=./snippets/services-2/java/src/main/java/io/dagger/modules/mymodule/MyModule.java ``` </TabItem> </Tabs>See it in action: