我正在使用docker-compose来构建WordPress环境。我的计划是使用作曲家来安装我需要的插件和主题。当我运行 docker-compose 构建时,一切正常,没有问题。当我运行docker-composup时,我看到我所有的容器都在运行,包括作曲家。当我导航到wordpress构建时,仅安装了默认主题和插件。我的问题是为什么没有安装我的插件和主题。我错过了什么?
我试图包含我认为相关的文件
文件结构
/
config/
/composer/
Dockerfile
composer.json
/wordpress/Dockerfile
/database/Dockerfile
/phpmyadmin/Dockerfile
dist/
/wp-content/
/themes/
/plugins/
/uploads/
docker-composer.yml
作曲家.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 Composer
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 Database
# 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: {}
正如我的评论中所解释的,您需要重新安排一些项目。
作曲家文件夹和服务可能会消失。在文件夹 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: {}
我希望这对你有用。否则让我知道错误,我会看看它。