Back to Dagger

Mount Copy Directory

docs/current_docs/partials/cookbook/filesystems/_mount-copy-directory.mdx

0.20.77.0 KB
Original Source

Mount or copy a directory or remote repository to a container

The following Dagger Function accepts a Directory argument, which could reference either a directory from the local filesystem or from a remote Git repository. It mounts the specified directory to the /src path in a container and returns the modified container.

:::note When working with private Git repositories, ensure that SSH authentication is properly configured on your Dagger 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>

An alternative option is to copy the target directory in the container. The difference between these two approaches is that mounts only take effect within your workflow invocation; they are not copied to, or included, in the final image. In addition, any changes to mounted files and/or directories will only be reflected in the target directory and not in the mount sources.

:::tip Besides helping with the final image size, mounts are more performant and resource-efficient. The rule of thumb should be to always use mounts where possible. :::

<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

  • Mount the /myapp host directory to /src in the container and return the modified container:

    <Tabs groupId="shell"> <TabItem value="System shell"> ```shell dagger -c 'mount-directory ./myapp/' ``` </TabItem> <TabItem value="Dagger Shell"> ```shell title="First type 'dagger' for interactive mode." mount-directory ./myapp/ ``` </TabItem> <TabItem value="Dagger CLI"> ```shell dagger call mount-directory --source=./myapp/ ``` </TabItem> </Tabs>
  • Mount the public dagger/dagger GitHub repository to /src in the container and return the modified container:

    <Tabs groupId="shell"> <TabItem value="System shell"> ```shell dagger -c 'mount-directory https://github.com/dagger/dagger#main' ``` </TabItem> <TabItem value="Dagger Shell"> ```shell title="First type 'dagger' for interactive mode." mount-directory https://github.com/dagger/dagger#main ``` </TabItem> <TabItem value="Dagger CLI"> ```shell dagger call mount-directory --source=https://github.com/dagger/dagger#main ``` </TabItem> </Tabs>
  • Mount the private user/foo GitHub repository to /src in the container and return the modified container:

    <Tabs groupId="shell"> <TabItem value="System shell"> ```shell dagger -c 'mount-directory ssh://[email protected]/user/foo#main' ``` </TabItem> <TabItem value="Dagger Shell"> ```shell title="First type 'dagger' for interactive mode." mount-directory ssh://[email protected]/user/foo#main ``` </TabItem> <TabItem value="Dagger CLI"> ```shell dagger call mount-directory --source=ssh://[email protected]/user/foo#main ``` </TabItem> </Tabs>
  • Mount the public dagger/dagger GitHub repository to /src in the container and list the contents of the directory:

    <Tabs groupId="shell"> <TabItem value="System shell"> ```shell dagger -c 'mount-directory https://github.com/dagger/dagger#main | directory /src | entries' ``` </TabItem> <TabItem value="Dagger Shell"> ```shell title="First type 'dagger' for interactive mode." mount-directory https://github.com/dagger/dagger#main | directory /src | entries ``` </TabItem> <TabItem value="Dagger CLI"> ```shell dagger call \ mount-directory --source=https://github.com/dagger/dagger#main \ directory --path=/src \ entries ``` </TabItem> </Tabs>
  • Copy the /myapp host directory to /src in the container and return the modified container:

    <Tabs groupId="shell"> <TabItem value="System shell"> ```shell dagger -c 'copy-directory ./myapp/' ``` </TabItem> <TabItem value="Dagger Shell"> ```shell title="First type 'dagger' for interactive mode." copy-directory ./myapp/ ``` </TabItem> <TabItem value="Dagger CLI"> ```shell dagger call copy-directory --source=./myapp/ ``` </TabItem> </Tabs>
  • Copy the public dagger/dagger GitHub repository to /src in the container and return the modified container:

    <Tabs groupId="shell"> <TabItem value="System shell"> ```shell dagger -c 'copy-directory https://github.com/dagger/dagger#main' ``` </TabItem> <TabItem value="Dagger Shell"> ```shell title="First type 'dagger' for interactive mode." copy-directory https://github.com/dagger/dagger#main ``` </TabItem> <TabItem value="Dagger CLI"> ```shell dagger call copy-directory --source=https://github.com/dagger/dagger#main ``` </TabItem> </Tabs>
  • Copy the private user/foo GitHub repository to /src in the container and return the modified container:

    <Tabs groupId="shell"> <TabItem value="System shell"> ```shell dagger -c 'copy-directory ssh://[email protected]/user/foo#main' ``` </TabItem> <TabItem value="Dagger Shell"> ```shell title="First type 'dagger' for interactive mode." copy-directory ssh://[email protected]/user/foo#main ``` </TabItem> <TabItem value="Dagger CLI"> ```shell dagger call copy-directory --source=ssh://[email protected]/user/foo#main ``` </TabItem> </Tabs>
  • Copy the public dagger/dagger GitHub repository to /src in the container and list the contents of the directory:

    <Tabs groupId="shell"> <TabItem value="System shell"> ```shell dagger -c 'copy-directory https://github.com/dagger/dagger#main | directory /src | entries' ``` </TabItem> <TabItem value="Dagger Shell"> ```shell title="First type 'dagger' for interactive mode." copy-directory https://github.com/dagger/dagger#main | directory /src | entries ``` </TabItem> <TabItem value="Dagger CLI"> ```shell dagger call \ copy-directory --source=https://github.com/dagger/dagger#main \ directory --path=/src \ entries ``` </TabItem> </Tabs>