Back to Dagger

Image From Dockerfile Build Context

docs/current_docs/partials/cookbook/builds/_image-from-dockerfile-build-context.mdx

0.20.71.6 KB
Original Source

Build image from Dockerfile using different build context

The following function builds an image from a Dockerfile with a build context that is different than the current working directory.

<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> </Tabs>

Example

Build an image from the source code in https://github.com/dockersamples/python-flask-redis using the Dockerfile from a different build context, at https://github.com/vimagick/dockerfiles#master:registry-cli/Dockerfile:

<Tabs groupId="shell"> <TabItem value="System shell"> ```shell dagger -c 'build https://github.com/dockersamples/python-flask-redis https://github.com/vimagick/dockerfiles#master:registry-cli/Dockerfile' ``` </TabItem> <TabItem value="Dagger Shell"> ```shell title="First type 'dagger' for interactive mode." build https://github.com/dockersamples/python-flask-redis https://github.com/vimagick/dockerfiles#master:registry-cli/Dockerfile ``` </TabItem> <TabItem value="Dagger CLI"> ```shell dagger call \ build --src="https://github.com/dockersamples/python-flask-redis" \ --dockerfile=https://github.com/vimagick/dockerfiles#master:registry-cli/Dockerfile ``` </TabItem> </Tabs>