Reputation: 1310
What is the proper syntax for a RUN
instruction in a Dockerfile
, that requires mounting a secret, in exec form?
In other words, if a Dockerfile
that looks something like:
FROM node:fermium-alpine
# . . .
RUN --mount=type=secret,id=npmrc yarn build:production
# . . .
how could the RUN
instruction above be converted from shell form to exec form? There doesn't seem to be an example in the official docs here.
Upvotes: 1
Views: 976
Reputation: 1310
FROM node:fermium-alpine
WORKDIR /usr/src/app
# . . .
RUN --mount=type=secret,id=npmrc,dst=/usr/src/app/.npmrc ["/usr/local/bin/yarn", \
"build:production"]
# . . .
Note:
--mount
flag is kept outside of the JSON array to its rightdst=. . .
has been added to the --mount
flag above to ensure that .npmrc
is not only saved as a dotfile, but that it is saved in the WORKDIR
so that yarn
can use it during the build
RUN
instructions with the --mount= . . .,dst=. . .
in exec form can get lengthy; use \
to split long lines in a Dockerfile
(taken from Dockerfile
best practices here)yarn
executable was replaced with the absolute path /usr/local/bin/yarn
for the node:fermium-alpine
imageUpvotes: 3