带有 Wordpress PVC 的 Kubernetes 获取旧的 Wordpress 文件
Kubernetes with Wordpress PVC get old Wordpress file
我已经用这个
为我的 wordpress 应用程序创建了一个 docker 图像
FROM wordpress:php7.4-apache
COPY . /var/www/html
在我将我的图片推送到我的私人仓库之后。当我 运行 我的新图像时,我的自定义 wordpress 文件在 /var/www/html
.
但是当我使用 pvc 在 kubernetes 中创建部署时,我在路径 /var/www/html 上的文件被 wordpress:php7.4-apache 映像
中的文件替换
我这样创建我的 pvc
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wp-pv-claim
namespace: custom
labels:
app: wordpress
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
我的部署看起来像
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
基于为下一代提供答案的评论中讨论的所有内容:)
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.
正确的 Dockerfile
应该包含 /usr/src/wordpress
路径而不是 /var/www/html
FROM wordpress:php7.4-apache
COPY . /usr/src/wordpress
我已经用这个
为我的 wordpress 应用程序创建了一个 docker 图像FROM wordpress:php7.4-apache
COPY . /var/www/html
在我将我的图片推送到我的私人仓库之后。当我 运行 我的新图像时,我的自定义 wordpress 文件在 /var/www/html
.
但是当我使用 pvc 在 kubernetes 中创建部署时,我在路径 /var/www/html 上的文件被 wordpress:php7.4-apache 映像
中的文件替换我这样创建我的 pvc
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wp-pv-claim
namespace: custom
labels:
app: wordpress
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
我的部署看起来像
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
基于为下一代提供答案的评论中讨论的所有内容:)
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.
正确的 Dockerfile
应该包含 /usr/src/wordpress
路径而不是 /var/www/html
FROM wordpress:php7.4-apache
COPY . /usr/src/wordpress