DEV Community

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

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
# 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
gasparev profile image
gasparev Author

Yep, that's a very good method if you are using multistage build. I talk about it here