Kubernetes (really the container runtime underneath) bind mounts a volume/directory from the host into the container. All files and sub directories in the containers target directory are hidden under the contents of the directory that is now mounted on top.
Do you really need a shared volume for this data? Is any of it being updated at runtime?
If you do need the shared data, you could add an initContainer
to your deployment and it can manage the copy of data to the volume. For complex scenarios, rsync
will usually have a flag for what you need to do.
initContainers:
- name: app
image: my/nginx:1.17
volumeMounts:
- name: app-data
mountPath: /app/data
- name: app-data
image: my/app:3.1.4
command: ["sh", "-c", "cp -r /app/dist/. /app/data"]
volumeMounts:
- name: app-data
mountPath: /app/data
It sounds like you are hosting an SPA. If the shared volume is simply to get the static built files into the nginx container, maybe inject the files into web server container at build rather than dealing with volumes.
FROM docker.io/node:12 AS build
WORKDIR /app
COPY . /app/
RUN yarn install && yarn build
FROM docker.io/nginx:1.17
COPY --from=build /app/dist/. /usr/share/nginx/html/
CMD [ "nginx", "-g", "daemon off;" ]