Write files from Docker without ownership and permission issues
Dominik Rüttiger
Some things you wish you knew beforehand. This very convenient method for writing files from Docker to a local filesystem without any ownership and permission issues, might be one of them.
It is a combination of a multi-stage Dockerfile and docker build --output
.
Typical use cases
- generating static websites with Astro
- generating slides from Markdown files with RevealJS
- generating PDFs with AsciiDoctor
Multi-stage Dockerfile
As an example, let’s create a Dockerfile to build a static Astro website:
FROM node:lts AS buildWORKDIR /appCOPY package*.json ./RUN npm installCOPY . .RUN npm run build
FROM scratch AS distCOPY --from=build /app/dist /
docker build —output
Let’s generate the website with the Docker build command:
docker buildx build --target dist --output dist --progress plain .
This will save the output into a local ./dist
folder.
Tags
#astro #devops #docker #dx #markdown