如何在Docker上更新Wordpress [英] How to update wordpress on docker

查看:289
本文介绍了如何在Docker上更新Wordpress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行php-fpm wordpress容器。

I'm running a php-fpm wordpress container.

wordpress源文件安装在与Nginx容器共享的命名卷 wordpress中。

The wordpress source files are mounted in a named volume "wordpress" shared with the Nginx container.

所有内容运行良好,除非需要将wordpress更新到新版本。命名卷内的代码将保留。对于命名卷来说,这是正常的。

Everything is running well except when i need to update wordpress to a new version. The code inside the named volume persists. It is normal for a named volume...

我可以手动删除该卷,但是必须有更好的方法。

I could manually delete the volume but there must be a better way.

我的dockerfile:

My dockerfile:

FROM wordpress:4.9.5-php5.6-fpm-alpine

我的docker-compose.yml

My docker-compose.yml

 version: '3.1'

services:

  php:
    build: ./docker/php/
    restart: unless-stopped
    volumes:
       - wordpress:/var/www/html
       - ./web/wp-content/:/var/www/html/wp-content/
       - ./web/wp-config.php:/var/www/html/wp-config.php

    environment:
       - DEBUG=${DEBUG:-0}
       - MYSQL_USER=$MYSQL_USER
       - MYSQL_PASSWORD=$MYSQL_PASSWORD
       - MYSQL_DATABASE=$MYSQL_DATABASE

  nginx:
    image: nginx:1-alpine
    restart: unless-stopped
    expose:
      - 80
    volumes:
      - wordpress:/var/www/html
      - ./web/wp-content/:/var/www/html/wp-content/
      - ./docker/nginx/site.conf:/etc/nginx/conf.d/default.conf
      - ./docker/nginx/wordpress.conf:/etc/nginx/wordpress.conf
    environment:
      - VIRTUAL_HOST=localhost

  mysql:
    image: mysql:5.6
    restart: unless-stopped
    environment:
        - MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD
        - MYSQL_USER=$MYSQL_USER
        - MYSQL_PASSWORD=$MYSQL_PASSWORD
        - MYSQL_DATABASE=$MYSQL_DATABASE
    volumes:
      - mysql:/var/lib/mysql

volumes:
  wordpress: {}
  mysql: {}

networks:
  default:
    external:
      name: wordpress

期待阅读您的建议

谢谢

推荐答案

感谢您的帮助。
有效。
这是我正在使用的代码。

Thank you for your help. It worked. Here is the code i'm using.

我在dockerfile中覆盖了入口点

I overriden the entrypoint in dockerfile

COPY check-wordpress-version.sh /usr/local/bin/

ENTRYPOINT ["check-wordpress-version.sh"]

这里是check-wordpress-version.sh的内容,用于检查wordpress的当前版本。

Here is the content of check-wordpress-version.sh to check wordpress current version.

VOLUME_VERSION="$(php -r 'require('"'"'/var/www/html/wp-includes/version.php'"'"'); echo $wp_version;')"
echo "Volume version : "$VOLUME_VERSION
echo "WordPress version : "$WORDPRESS_VERSION

if [ $VOLUME_VERSION != $WORDPRESS_VERSION ]; then
    echo "Forcing WordPress code update..."
    rm -f /var/www/html/index.php
fi

docker-entrypoint.sh php-fpm

这篇关于如何在Docker上更新Wordpress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆