You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ability to define and share a known location within the host during both build and runtime.
The rationale for this being to improve development experience. Many of us bind mount into containers during development so to be able to share package management caches etc during image builds and development workflows without the need to keep rebuilding etc images could improve outputs.
A diagram to explain, (albeit quite crude)
Possible Solutions
Using this Dockerfile as an example
Important to note: Due to multi-stage and moving compiled assets into an alpine image, all caches created by composer are lost. This is fine, we want clean/slim builds in production, but during development those caches could speed things up.
# syntax = docker/dockerfile:1.0-experimental
ARG COMPOSER_VERSION=latest
FROM composer:${COMPOSER_VERSION} as composer
# Set the work dir to something reflective of the image
WORKDIR /code
# Add the composer manifests
COPY composer.json composer.json
COPY composer.lock composer.lock
# Build the source
# Using the cache mount.. here we define a hostPath, a known directory within the build context
RUN composer install -v
# Move final assets into streamlined alpine image
# Moving to scratch causes too many headaches..
FROM alpine:latest
WORKDIR /code
COPY --from=composer /code /code
Option 1 - Defining host path on cache mount
One option to achieve this could be to allow the definition of the hostPath when mounting cache.
Updating the above Dockerfiles RUN command
RUN --mount=type=cache,target=$COMPOSER_HOME/cache,hostPath=./dir-in-context \
composer install -v;
Option 2 - Allowing bind mount to write to host
Another option could be allow bind mounts to write back to the host during image build. As far as im aware, currently you can files into an image during build with bind mounts, but images cannot push back onto the host.
Add a persist flag to bind mounts to allow 2-way writes, ie from host to image, from image to host
Updating the above Dockerfiles RUN command
RUN --mount=type=bind,source=./path-in-context,target=$COMPOSER_HOME/cache,readwrite,persist \
composer install -v;
Usage at runtime
Having a known cache location on the host, in both options above ./dir-in-context, that same directory can be mounted into containers on runtime.
$ docker run --rm --volume=./dir-in-context:/tmp/cache composer:latest
Runtime mounts can be 2-way so as the command updates the mounted directory, those new files can be pushed back into image builds and the cycle continues.
The text was updated successfully, but these errors were encountered:
Aim
The ability to define and share a known location within the host during both build and runtime.
The rationale for this being to improve development experience. Many of us bind mount into containers during development so to be able to share package management caches etc during image builds and development workflows without the need to keep rebuilding etc images could improve outputs.
A diagram to explain, (albeit quite crude)
Possible Solutions
Using this Dockerfile as an example
Important to note: Due to multi-stage and moving compiled assets into an alpine image, all caches created by composer are lost. This is fine, we want clean/slim builds in production, but during development those caches could speed things up.
Option 1 - Defining host path on cache mount
One option to achieve this could be to allow the definition of the
hostPath
when mounting cache.Updating the above Dockerfiles RUN command
Option 2 - Allowing bind mount to write to host
Another option could be allow bind mounts to write back to the host during image build. As far as im aware, currently you can files into an image during build with bind mounts, but images cannot push back onto the host.
Add a
persist
flag to bind mounts to allow 2-way writes, ie from host to image, from image to hostUpdating the above Dockerfiles RUN command
Usage at runtime
Having a known cache location on the host, in both options above
./dir-in-context
, that same directory can be mounted into containers on runtime.Runtime mounts can be 2-way so as the command updates the mounted directory, those new files can be pushed back into image builds and the cycle continues.
The text was updated successfully, but these errors were encountered: