DEV Community

Discussion on: Advanced Docker: how to use secrets the right way

Collapse
 
aghost7 profile image
Jonathan Boudreau

This is still experimental and shouldn't be used for production builds. If you want to use secrets you should use multi-stage builds. For example:

FROM node:12 as base

FROM base as build
COPY ./keys/id_rsa /root/.ssh/id_rsa
WORKDIR /app
# some private repositories are listed in the dependencies
COPY ./package.json /app/package.json
# install private packages
RUN npm install

FROM base
COPY --from=build /app/node_modules /app/node_modules
Enter fullscreen mode Exit fullscreen mode
Collapse
 
gasparev profile image
gasparev

Yep, that's a very good method if you are using multistage build. I talk about it here gasparevitta.com/posts/advanced-do...