Nginx+php-fpm docker镜像合二为一

来自linux中国网wiki
Evan讨论 | 贡献2021年9月4日 (六) 08:59的版本 →‎my wordpress
跳到导航 跳到搜索

进阶见 Alpine#alpine lnmp 也为docker准备

https://github.com/evan886/alpine-dockerbuild/tree/main/alpine_nginx_php7.4



docker build -t evan886/alpine_nginx_php7.4:v3.14 .

docker push  evan886/alpine_nginx_php7.4:v3.14

docker run -it  --name alpine_nginx_php7.3 -p 80:80 alpine_nginx_php7.3:1 .
docker run -it  --name alpine_nginx_php7.3 -p 80:80 id
域名 默认为wp.linuxsa.org 

目录其实就是 /var/www/html


还有个  
docker pull evan886/wp:v5.8

docker build -t evan886/wp:v5.8  .

 tree .
.
├── Dockerfile
├── usage
└── wordpress-5.8-zh_CN.tar.gz


cat Dockerfile 
FROM evan886/alpine_nginx_php7.4:v3.14
#ADD default.conf /etc/nginx/conf.d/
ADD wordpress-5.8-zh_CN.tar.gz  /var/www/html/
RUN chown www-data:www-data -R /var/www/html


 docker run --name wp  -p80:80 -d 54254a4fbae1

http://wp.linuxsa.org/wordpress/wp-admin/setup-config.php



troubleshooting


为什么老是 403呢  
403 Forbidden
ng 配置 添加 index.php 放在 第二位 


c3 (cannot be forced) - image has dependent child images
 要先删除 wp 


注意  al ng include 没开启到我要的defaul  上面说在3.15会开启 
现在开的默认的是报错的 nginx.conf 放太多server 


拷贝到容器中

docker cp test.php alpine_nginx_php7.3:/var/www/html/

docker cp evan.php  some-nginx:/var/www/html

my wordpress

cat  aliyun/ng-dp.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: evan886/wp:v5.8
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: ngx-service
  labels:
    app: nginx
spec:
  type: NodePort
  selector:
    app: nginx
  ports:
  - port: 80
    targetPort: 80
    nodePort: 32500


访问 http://192.168.88.70:32500/wordpress/wp-admin/setup-config.php

http://wp.linuxsa.org/wordpress/wp-admin/setup-config.php

TKE yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
    description: wp测试
  creationTimestamp: "2021-09-04T08:45:03Z"
  generation: 1
  labels:
    k8s-app: wordpress
    qcloud-app: wordpress
  managedFields:
  - apiVersion: apps/v1
    manager: tke-apiserver
    operation: Update
    time: "2021-09-04T08:45:03Z"
  - apiVersion: apps/v1
    manager: kube-controller-manager
    operation: Update
    time: "2021-09-04T08:45:12Z"
  name: wordpress
  namespace: default
  resourceVersion: "511239899"
  selfLink: /apis/apps/v1/namespaces/default/deployments/wordpress
  uid: 254856f1-2f61-49e8-9d70-a577a69a87ce
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      k8s-app: wordpress
      qcloud-app: wordpress
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        k8s-app: wordpress
        qcloud-app: wordpress
    spec:
      containers:
      - env:
        - name: PATH
          value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
        - name: PHPIZE_DEPS
          value: "autoconf \t\tdpkg-dev dpkg \t\tfile \t\tg++ \t\tgcc \t\tlibc-dev \t\tmake \t\tpkgconf \t\tre2c"
        - name: PHP_INI_DIR
          value: /usr/local/etc/php
        - name: PHP_EXTRA_CONFIGURE_ARGS
          value: --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data --disable-cgi
        - name: PHP_CFLAGS
          value: -fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
        - name: PHP_CPPFLAGS
          value: -fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
        - name: PHP_LDFLAGS
          value: -Wl,-O1 -pie
        - name: GPG_KEYS
          value: 42670A7FE4D0441C8E4632349E4FDC074A4EF02D 5A52880781F755608BF815FC910DEB46F53EA312
        - name: PHP_VERSION
          value: 7.4.22
        - name: PHP_URL
          value: https://www.php.net/distributions/php-7.4.22.tar.xz
        - name: PHP_ASC_URL
          value: https://www.php.net/distributions/php-7.4.22.tar.xz.asc
        - name: PHP_SHA256
          value: 8e078cd7d2f49ac3fcff902490a5bb1addc885e7e3b0d8dd068f42c68297bde8
        image: ccr.ccs.tencentyun.com/evan/k8s:wpv5.8
        imagePullPolicy: IfNotPresent
        name: wp
        resources:
          limits:
            cpu: 500m
            memory: 1Gi
          requests:
            cpu: 250m
            memory: 256Mi
        securityContext:
          privileged: false
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      imagePullSecrets:
      - name: qcloudregistrykey
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
status:
  availableReplicas: 1
  conditions:
  - lastTransitionTime: "2021-09-04T08:45:12Z"
    lastUpdateTime: "2021-09-04T08:45:12Z"
    message: Deployment has minimum availability.
    reason: MinimumReplicasAvailable
    status: "True"
    type: Available
  - lastTransitionTime: "2021-09-04T08:45:03Z"
    lastUpdateTime: "2021-09-04T08:45:12Z"
    message: ReplicaSet "wordpress-5977dc5976" has successfully progressed.
    reason: NewReplicaSetAvailable
    status: "True"
    type: Progressing
  observedGeneration: 1
  readyReplicas: 1
  replicas: 1
  updatedReplicas: 1

see also

nginx+php-fpm docker镜像合二为一

on qcloud nginx+php-fpm docker镜像合二为一

docker中nginx容器和php容器混合运行

为多个PHP-FPM容器量身打造单一Nginx镜像的方法


基于Alpine构建php7.0.27镜像的dockerfile

Alpine(apk add)从零搭建 php7.2-fpm + nginx

使用 docker 搭建 nginx+php-fpm 环境 (两个独立镜像)