0

I have create a docker image for my wordpress application with just this

FROM wordpress:php7.4-apache
COPY . /var/www/html

after i have push my image on my private repo. When i run my new image the file of my custom wordpress are well in the /var/www/html.

but when i create a deploy in kubernetes with pvc my file on path /var/www/html is replace by the file from the wordpress:php7.4-apache image

i create my pvc like this

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: wp-pv-claim
      namespace: custom
      labels:
        app: wordpress
    spec:
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 20Gi

and my deploy look like

apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: custom
  name: wordpress
  labels:
    app: wordpress
spec:
  replicas: 1
  selector:
    matchLabels:
      app: wordpress
  template:
    metadata:
      labels:
        app: wordpress
    spec:
      containers:
        - image: privaterepo.azurecr.io/custom:latest
          name: wordpress
          env:
            - name: WORDPRESS_DB_HOST
              value: mysqlhost
            - name: DB_HOST
              value: mysqlhost
            - name: WORDPRESS_DB_USER
              value: mysqluser
            - name: DB_USER
              value: mysqluser
            - name: WORDPRESS_DB_PASSWORD
              value: mysqlpassword
            - name: DB_PASS
              value: mysqlpassword
            - name: WORDPRESS_DB_NAME
              value: dbname
            - name: DB_NAME
              value: dbname
            - name: WORDPRESS_TABLE_PREFIX
              value: wp
          ports:
            - containerPort: 80
              name: client
          volumeMounts:
            - name: wordpress-persistent-storage
              mountPath: /var/www/html
      volumes:
        - name: wordpress-persistent-storage
          persistentVolumeClaim:
            claimName: wp-pv-claim
Alessio
  • 3,404
  • 19
  • 35
  • 48
john
  • 468
  • 1
  • 9
  • 26
  • can you try update your .spec.containers. with `imagePullPolicy: Always` and try again? This will allow you to be sure of using the latest image. I have a strong feeling that you still use your first non-edited image. ISince you are using `latest` image tag(and I guess you dont have image versioning) + default `imagePullPolicy: IfNotPresent` - `kubelet` skip pulling an already existed image. – Vit Feb 06 '20 at 16:03
  • 1
    another guess: you deployed first time the same with the default wordpress image. Then you decided to modify your image, so you deleted deployment, updated the image and deployed again. But you forgot remove old PVC that still contains old `/var/www/html` data. As a result you still use old PVC with old data for each new deployment. Solution is to delete PVC and recreate it along with the deployment. – Vit Feb 06 '20 at 16:08
  • i find it's because i need to copy the file in /usr/src/wordpress/ and after in the file is copy to /var/www/html it's for this my file was overrider – john Feb 06 '20 at 21:00

1 Answers1

1

Based on everything that was discussed in comments providing the answer for next generations :)

As per monachus/wordpress

What's wrong with Wordpress's Docker image?

The container shipped by Wordpress copies over the contents of /usr/src/wordpress to /var/www/html when the container is first created, but only if no content already exists in /var/www/html. This means that if you've already deployed the container and have a persistent volume mounted at that location, you can upgrade your container from 4.7.4 to 4.8.1, and although it claims to be 4.8.1, nothing happens.

Correct Dockerfile should contain /usr/src/wordpress path instead of /var/www/html

FROM wordpress:php7.4-apache
COPY . /usr/src/wordpress
Community
  • 1
  • 1
Vit
  • 7,740
  • 15
  • 40