How do I copy Docker WordPress files from initContainer into an emptyDir in Kubernetes? How do I copy Docker WordPress files from initContainer into an emptyDir in Kubernetes? kubernetes kubernetes

How do I copy Docker WordPress files from initContainer into an emptyDir in Kubernetes?


Your data is not being copied because your docker cmd is overwritten by args yaml field.

Docker entrypoint exec requires php-fpm to be passed as an further argument in order to trigger the code that generates the word press files.

After some testing i find a way to address your question.It is a more workaround than solution but it solves your problem.

So to trigger code generation you have to set the first parameter to php-fpm. In the example below I'm using -v parameter so the programs exist immediately. If you don`t pass any arguments it would start and hold init container from exiting.

initContainers:  - args:     - php-fpm     - -v

Now the last part is tho address the issues with copying files. I have removed the cp args and mounted EmptyDir into /var/www/html. Now the files are being generated directly to your desired volume so there no need to copying the files afterwards.

 initContainers:   volumeMounts:    - name: shared-wordpress      mountPath: /var/www/html


If you need to Configure a Pod Initialization, check if command format shown in the documentation example could help, when applied to your case:

command:    - cp    - "-r"    - "/var/www/html/."    - "/shared-wordpress"