---
slug: /quickstart/429462/build-dockerfile
displayed_sidebar: "quickstart"
hide_table_of_contents: true
title: "Reuse existing Dockerfiles"
---

# Quickstart

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";
import QuickstartDoc from '@site/src/components/quickstartDoc.js'
import Embed from '@site/src/components/embed.js'

export const ids = {
    Go: "gFFeUi06wW3",
    "Node.js": "AnwtJTV9Xj3",
    Python: "EaSvAH9iPiG"
}

<QuickstartDoc embeds={ids}>

## Reuse existing Dockerfiles

As you've seen over the last few pages, Dagger is a powerful tool. It lets you create CI pipelines using general purpose programming languages, giving you full access to native control structures like conditionals and loops. By allowing you to import and use existing language extensions or packages in your pipeline code, Dagger makes it easier to quickly add new functionality or integrate with third-party services. By the same token, Dagger pipelines also benefit from static typing and easier refactoring.

However, rewriting your entire CI/CD system to use Dagger, all at once and without breaking compatibility, is not an easy task.

The good news here is that Dagger can natively run Dockerfiles with full compatibility. This means that it's easy to wrap your existing Dockerfile in a Dagger pipeline, and gradually refactor it over time, without breaking your team's workflow.

The example application repository includes a simple Dockerfile. Use it with a Dagger pipeline as shown below:

<Tabs groupId="language" className="embeds">
<TabItem value="Go">

<Embed id="gFFeUi06wW3"/>

This code listing does the following:

- It creates a Dagger client with `Connect()`.
- It uses the client's `Host().Directory()` method to obtain a reference to the source code directory on the host.
- It uses the `Directory` object's `DockerBuild()` method to build a new container using a Dockerfile. This method defaults to using the Dockerfile located at `./Dockerfile` in the directory passed to it as argument and returns the built `Container` object.
- It uses the `Container` object's `Publish()` method to publish the container to [ttl.sh](https://ttl.sh). As before, to prevent name collisions, the container image name is suffixed with a random number.

Run the pipeline by executing the command below from the application directory:

```shell
dagger run go run ci/main.go
```

</TabItem>
<TabItem value="Node.js">

<Embed id="AnwtJTV9Xj3"/>

This code listing does the following:

- It creates a Dagger client with `connect()`.
- It uses the client's `host().directory()` method to obtain a reference to the source code directory on the host.
- It uses the `Directory` object's `dockerBuild()` method to build a new container using a Dockerfile. This method defaults to using the Dockerfile located at `./Dockerfile` in the directory passed to it as argument and returns the built `Container` object.
- It uses the `Container` object's `publish()` method to publish the container to [ttl.sh](https://ttl.sh). As before, to prevent name collisions, the container image name is suffixed with a random number.

Run the pipeline by executing the command below from the application directory:

```shell
dagger run node ci/index.mjs
```

</TabItem>
<TabItem value="Python">

<Embed id="EaSvAH9iPiG"/>

This code listing does the following:

- It creates a Dagger client with `with dagger.Connection()`.
- It uses the client's `host().directory()` method to obtain a reference to the source code directory on the host.
- It uses the `Directory` object's `docker_build()` method to build a new container using a Dockerfile. This method defaults to using the Dockerfile located at `./Dockerfile` in the directory passed to it as argument and returns the built `Container` object.
- It uses the `Container` object's `publish()` method to publish the container to [ttl.sh](https://ttl.sh). As before, to prevent name collisions, the container image name is suffixed with a random number.

Run the pipeline by executing the command below from the application directory:

```shell
dagger run python ci/main.py
```

</TabItem>
</Tabs>

After Dagger resolves the pipeline, the newly-built container image will be available in the [ttl.sh](https://ttl.sh) registry. Download and test it as described in the section on [publishing the application](./730264-publish.mdx).

</QuickstartDoc>
