#Mounting volumes into the DockerBuild() context

1 messages · Page 1 of 1 (latest)

shell tendon
#

Hi there,

I'm exploring a situation where I can gain a fair amount of performance by being able to use CacheVolumes in the creation process of a Container via DockerBuild().

For example, consider the a fake Dockerfile like

FROM nodejs:18

WORKDIR /app
COPY . /app

RUN yarn install

If I were to have a cache volume for node_modules, I could expedite this image creation time. As I understand it, though, this is against the Dagger pattern.

Any suggestion or possibility for ways to magically mount into the docker context before/during build time?

polar bronze
#

hey @shell tendon, it's not against the Dagger pattern at all. You can use standard Dockerfiles volumes with your RUN command and that'll work just fine

#

in your test example, you can do

FROM nodejs:18

WORKDIR /app
COPY . /app

RUN --mount=type=cache,target=/my/app/node_modules yarn install
#

We generally suggest migrating your Dockerfiles to Dagger code so you have more control about your pipeline. But wrapping them to start also works 🙌

shell tendon
#

I’m a big fan of converting to dagger, we’re just in a situation where dagger is an implementation layer for a CI service that builds images, so we don’t have control over the dockerfiles we take as input.