作曲家未通过Dockerfile安装Wordpress插件

时间:2019-04-23 03:46:21

标签: docker-compose composer-php dockerfile

我正在使用docker-compose构建wordpress环境。我的计划是使用composer安装所需的插件和主题。当我运行docker-compose build时,一切正常,没有问题。当我运行docker-compose up时,我看到我所有的容器都在运行,包括composer。当我导航到wordpress版本时,仅安装默认主题和插件。我的问题是为什么没有安装我的插件和主题。我想念什么?

我尝试包含我认为相关的文件

文件结构

/
 config/
   /composer/
      Dockerfile
      composer.json
   /wordpress/Dockerfile
   /database/Dockerfile
   /phpmyadmin/Dockerfile

 dist/
   /wp-content/
      /themes/
      /plugins/
      /uploads/

docker-composer.yml

composer.json

{
  "repositories":[
    {
        "type":"composer",
        "url":"https://wpackagist.org"
    }
  ],
  "require": {
    "wpackagist-plugin/akismet":"dev-trunk",
    "wpackagist-plugin/wordpress-seo":">=7.0.2",
    "wpackagist-theme/hueman":"*"
  }
}

Dockerfile编写器

FROM composer/composer:php7

# Install composer
WORKDIR /var/www/html/wp-content

RUN curl -sS https://getcomposer.org/installer | \
    php -- --install-dir=/usr/bin/ --filename=composer

COPY composer.json /var/www/html/wp-content
# COPY composer.lock ./
RUN composer install --no-scripts --no-autoloader
# COPY ./ /var/www/
RUN composer dump-autoload --optimize

Dockerfile Wodrpess

# start with the latest wordpress and php image
FROM wordpress:5.1.1-php7.3-apache

# Set our environment variables for logging into wordpress
ENV WORDPRESS_DB_HOST database:3306
ENV WORDPRESS_DB_USER username
ENV WORDPRESS_DB_PASSWORD password

# Expose a port to run on
EXPOSE 80

Dockerfile数据库

# start with the mysql image
FROM mysql:5.7

# Set our environment varibales for logging into the DB
ENV MYSQL_ROOT_PASSWORD UKoBMndyEY
ENV MYSQL_DATABASE wordpress
ENV MYSQL_USER username
ENV MYSQL_PASSWORD password

# Copy the database table dependencies into our image DB
COPY  ./includes /docker-entrypoint-initdb.d

# Expose a port to run on
EXPOSE 3306:3306

docker-compose.yml

version: "3.3"
services:
  wordpress:
    build:
      context: ./config/docker/wordpress
    volumes:
      - ./dist/wp-content:/var/www/html/wp-content
    ports:
      - "8080:80"
    restart: always
    working_dir: /var/www/html
    depends_on:
      - database
  database:
    build:
      context: ./config/docker/database
    volumes:
      - datab:/var/lib/mysql
    restart: always
  composer:
    build:
      context: ./config/docker/composer
    restart: 'no'
    image: "composer"
    volumes:
      - ./dist/wp-content:/var/www/html/wp-content
  phpmyadmin:
    build:
        context: ./config/docker/phpmyadmin
    ports:
      - 8181:80
    restart: always
    depends_on:
      - database
volumes:
    datab: {}

1 个答案:

答案 0 :(得分:1)

如我的评论中所述,您需要重新安排项目。

composer文件夹和服务可能会消失。将文件夹编辑器的内容移至wordpress文件夹中。

然后wordpress文件夹中的Dockerfile应该如下所示:

FROM composer/composer:php7 as build

# Install composer
WORKDIR /var/www/html/wp-content

RUN curl -sS https://getcomposer.org/installer | \
    php -- --install-dir=/usr/bin/ --filename=composer

COPY composer.json /var/www/html/wp-content
# COPY composer.lock ./
RUN composer install --no-scripts --no-autoloader
# COPY ./ /var/www/
RUN composer dump-autoload --optimize

FROM wordpress:5.1.1-php7.3-apache

# Set our environment variables for logging into wordpress
ENV WORDPRESS_DB_HOST database:3306
ENV WORDPRESS_DB_USER username
ENV WORDPRESS_DB_PASSWORD password

COPY --from=build /var/www/html/wp-content /var/www/html/wp-content

# Expose a port to run on
EXPOSE 80

现在可以像这样简化docker-compose.yml:

version: "3.3"
services:
  wordpress:
    build:
      context: ./config/docker/wordpress
    ports:
      - "8080:80"
    restart: always
    working_dir: /var/www/html
    depends_on:
      - database
  database:
    build:
      context: ./config/docker/database
    volumes:
      - datab:/var/lib/mysql
    restart: always
  phpmyadmin:
    build:
        context: ./config/docker/phpmyadmin
    ports:
      - 8181:80
    restart: always
    depends_on:
      - database
volumes:
    datab: {}

我希望这对您有用。否则让我知道该错误,我将对其进行处理。