【发布时间】:2019-09-22 01:54:18
【问题描述】:
我正在构建一个包含 composer magento 安装的 php 映像。内容存储在图像的 /var/www/html 中。现在我有一个 PHP-Image 和一些部署文件。但是图像 /var/www/html 文件夹的内容不会显示在任何创建的 POD 中。首先我在想,我必须在 PHP 图像中创建一个卷,映射到 /var/www/html 路径。但这并没有帮助(但对我来说这似乎是合乎逻辑的)。
也许永久卷声明存在问题?我读到,我必须在 php 和 nginx 容器中创建一个具有相同 /var/www/html 路径的卷,以便 php 内容可以由 nginx 执行,所以我这样做了。但现在我不确定这是否真的是这样做的方法,它会干扰 PVC。
PHP Docker-Image
# image
FROM php:7.1-fpm
# envs
ENV INSTALL_DIR /var/www/html
# install composer
RUN curl -sS https://getcomposer.org/installer | php \
&& mv composer.phar /usr/local/bin/composer
# install libraries
... shortended ...
# set memory limits
RUN echo "memory_limit=2048M" > /usr/local/etc/php/conf.d/memory-limit.ini
# clean apt-get
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# www-data should own /var/www
RUN chown -R www-data:www-data /var/www
# switch user to www-data
USER www-data
# copy sources with proper user
COPY --chown=www-data ./magento2/composer $INSTALL_DIR
# set working dir
WORKDIR $INSTALL_DIR
RUN composer install
# chmod directories
RUN chmod u+x bin/magento
# switch back
USER root
VOLUME $INSTALL_DIR
部署 1。持久卷声明
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-volume-magento
spec:
capacity:
storage: 50Gi
accessModes:
- ReadWriteOnce
2。 PHP 部署(将构建映像与 Web 应用程序一起使用)
apiVersion: apps/v1
kind: Deployment
metadata:
name: php
labels:
app: php
spec:
replicas: 1
selector:
matchLabels:
app: php
template:
metadata:
labels:
app: php
tier: frontend
spec:
containers:
- name: php-mage
image: php-mage:latest
imagePullPolicy: Never
volumeMounts:
- name: magento2-persistent-storage
readOnly: false
mountPath: /var/www/html
volumes:
- name: magento2-persistent-storage
persistentVolumeClaim:
claimName: magento2-volumeclaim
3. Nginx 部署
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
tier: frontend
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
- containerPort: 443
volumeMounts:
- name: magento2-persistent-storage
readOnly: false
mountPath: /var/www/html
- name: nginx-config-volume
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
- name: nginx-site-config-volume
mountPath: /etc/nginx/sites-enabled/default.conf
subPath: default.conf
- name: fastcgi-snippet-volume
mountPath: /etc/nginx/snippets/fastcgi-php.conf
subPath: fastcgi-php.conf
volumes:
- name: magento2-persistent-storage
persistentVolumeClaim:
claimName: magento2-volumeclaim
- name: nginx-config-volume
configMap:
name: nginx-config
- name: nginx-site-config-volume
configMap:
name: nginx-site-config
- name: fastcgi-snippet-volume
configMap:
name: nginx-fastcgi-config
编辑: 我意识到,当我在 php-deployment.yaml 中使用 subPath 时:
volumeMounts:
- name: magento2-persistent-storage
readOnly: false
mountPath: /var/www
subPath: html
我的内容在 PHP Pod 中可用。但是我无法在nginx部署中添加相同的逻辑,因为它会覆盖内容,文件夹又是空的。
现在,更进一步,但仍然是如何正确执行此操作的问题。 我必须在 nginx 和 php 之间共享一个 mountPath 吗?
【问题讨论】:
标签: php docker nginx deployment kubernetes