Write Build Output from Docker Container to Host

Viewed 377

I have a simple dockerfile like this

# develop stage
FROM node:alpine as develop-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .

# build stage
FROM develop-stage as build-stage
RUN npm run build

and I am pretty sure in the container there's /app/dist as the built artifact after docker run finishes, and I would like to export it from the container to the outside host system by using a volume like this:

docker run -v $(pwd)/artifacts:/app/dist test-vue 

but nothing writes to the artifacts directory that I created. Any thoughts?

1 Answers

Using -v $(pwd)/artifacts:/app/dist will replace the content of the container by the host's content.

Documentation

If you bind-mount into a non-empty directory on the container, the directory’s existing contents are obscured by the bind mount.

If you want to export you need to copy the files into a volume after the container started. There are some samples for back/restore volume here.

docker exec <container> cp <src> <dst>
Related