docs/current_docs/partials/cookbook/filesystems/_mount-copy-directory.mdx
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">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">Examples
Mount the /myapp host directory to /src in the container and return the modified container:
Mount the public dagger/dagger GitHub repository to /src in the container and return the modified container:
Mount the private user/foo GitHub repository to /src in the container and return the modified container:
Mount the public dagger/dagger GitHub repository to /src in the container and list the contents of the directory:
Copy the /myapp host directory to /src in the container and return the modified container:
Copy the public dagger/dagger GitHub repository to /src in the container and return the modified container:
Copy the private user/foo GitHub repository to /src in the container and return the modified container:
Copy the public dagger/dagger GitHub repository to /src in the container and list the contents of the directory: