Write files from Docker without ownership and permission issues
Dominik Rüttiger 1 min read
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
As an example, let’s create a Dockerfile to build a static Astro website:
FROM node:lts AS build WORKDIR /app COPY package*.json ./ RUN npm install COPY . . RUN npm run build FROM scratch AS dist COPY --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
Twitter Hacker News Reddit