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

Multi-stage Dockerfile

As an example, let’s create a Dockerfile to build a static Astro website:

FROM node:lts AS build
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 ./dist folder.


#astro #devops #docker #dx #markdown


Twitter LinkedIn Hacker News Reddit