Reputation:
My openshift template with pv,pvc and deployment config is as follows:
kind: Template
apiVersion: v1
metadata:
name: okd-static-server.
labels:
template: okd-static-server
objects:
- apiVersion: v1
kind: PersistentVolume
metadata:
name: okd-static-volume
spec:
storageClassName: manual
capacity:
storage: 1Gi
persistentVolumeReclaimPolicy: Retain
accessModes:
- ReadWriteMany
nfs:
path: /mnt/k8smount/static
server: <nfs_server_ip>
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: okd-static-volume
creationTimestamp: null
spec:
storageClassName: manual
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
volumeName: okd-static-volume
- apiVersion: v1
kind: DeploymentConfig
metadata:
creationTimestamp: null
generation: 2
labels:
app: okd-static-server
name: okd-static-server
spec:
replicas: 1
selector:
app: okd-static-server
deploymentconfig: okd-static-server
strategy:
type: Rolling
template:
metadata:
creationTimestamp: null
labels:
app: okd-static-server
deploymentconfig: okd-static-server
spec:
containers:
- image: okd-static-server:dev1.0.0
imagePullPolicy: Always
name: okd-static-server
resources: {}
volumeMounts:
- mountPath: /usr/share/nginx
name: okd-static
restartPolicy: Always
volumes:
- name: okd-static
persistentVolumeClaim:
claimName: okd-static-volume-claim
The image okd-static-server:dev1.0.0
which is used above in the deployment config is built using the following dockerfile
FROM nginx:1.16-alpine
RUN mkdir -p /var/run/nginx /var/log/nginx /var/cache/nginx && \
chown -R nginx:0 /var/run/nginx /var/log/nginx /var/cache/nginx && \
chmod -R g=u /var/run/nginx /var/log/nginx /var/cache/nginx
ADD static/ /usr/share/nginx
COPY nginx.conf /etc/nginx/nginx.conf
COPY default.conf /etc/nginx/conf.d/default.conf
ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
USER nginx:nginx
EXPOSE 8000
CMD ["nginx","-g","daemon off;"]
As mentioned in the above dockerfile, during the docker image build the static content is copied to the folder /usr/share/nginx
of the image.
The image folder: /usr/share/nginx
is mounted to the nfs mount directory /mnt/k8smount/static
which could be observed from the openshift template above.
Initally the nfs mount directory will be empty. The issue here im facing is once the built image is deployed using the above openshift template, the nfs mount directory is not having the expected static contents. Instead it is empty.
Note: Manually adding content to nfs mount directory will populate the content to container folder: /usr/share/nginx
.
Openshift/okd version: 3.11
Upvotes: 2
Views: 742
Reputation: 46
When you build the docker image, the ADD command gets executed and data is copied to /usr/share/nginx
folder. At this point, the image does not have any information that you intend this to be a mount point to NFS. You cannot copy data from a static folder to a volume through ADD
command in the dockerfile.
You could have the static data available in your container on a local folder.
Upvotes: 0