You'll need experimental software (as of writing) for doing this.
First of all, you have to create a buildx builder instance:
docker buildx create --name insecure --driver docker-container \
--driver-opt image=moby/buildkit:master \
--buildkitd-flags '--allow-insecure-entitlement security.insecure \
--allow-insecure-entitlement network.host'
As of today, the latest release (v0.9.0) of buildkit doesn't have the --insecure
support, so you need master
.
You should issue this command as the user which does the build.
Then you'll need to add these to your Dockerfile
:
# syntax = docker/dockerfile:experimental
RUN --security=insecure mkdir /nfs && \
mount -t nfs -o nolock -o vers=4 $SERVER_IP:/nfs /nfs && \
ls -la /nfs
Third, you have to do your build with buildx
and give the following options (--allow
and --builder
along with your normal options):
docker buildx build --allow security.insecure,network.host \
--builder insecure \
-t image:tag --file=Dockerfile .
You should then have your NFS server mounted at /nfs
.
Be aware that this mount will be present only in the same RUN
context, because all those steps run in a different container. The next RUN
line will see only an empty /nfs
directory.
So you should do everything which needs data from /nfs
from that RUN
step!