Docker compose 将WP-CLI容器添加到LEMP堆栈
我有一个工作的LEMP堆栈和下面的docker compose文件Docker compose 将WP-CLI容器添加到LEMP堆栈,docker-compose,dockerfile,Docker Compose,Dockerfile,我有一个工作的LEMP堆栈和下面的docker compose文件 Docker version 18.09.1, build 4c52b90 Distributor ID: Ubuntu Description: Ubuntu 18.04.1 LTS Release: 18.04 Codename: bionic PHP映像的Dockerfile包含以下内容 version: "3.7" services: php: build:
Docker version 18.09.1, build 4c52b90
Distributor ID: Ubuntu
Description: Ubuntu 18.04.1 LTS
Release: 18.04
Codename: bionic
PHP映像的Dockerfile包含以下内容
version: "3.7"
services:
php:
build:
context: './config/php/'
networks:
- dev
volumes:
- /WORK/:/var/www/html/
working_dir: /var/www/html/
container_name: php
nginx:
image: nginx:1.14-alpine
depends_on:
- php
- mysql
networks:
- dev
ports:
- "80:80"
volumes:
- ./config/nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro
- /WORK/:/var/www/html/
container_name: nginx
mysql:
image: mysql:5.7
restart: always
ports:
- "3306:3306"
volumes:
- /MYSQL/:/var/lib/mysql
networks:
- dev
environment:
MYSQL_ROOT_PASSWORD: "db_root"
MYSQL_DATABASE: "test_db"
MYSQL_USER: "test_db_user"
MYSQL_PASSWORD: "test_db_pass"
container_name: mysql
wpcli:
image: wordpress:cli
depends_on:
- mysql
environment:
WORDPRESS_DB_HOST: mysql
WORDPRESS_DB_NAME: test_db
WORDPRESS_DB_USER: test_db_user
WORDPRESS_DB_PASSWORD: test_db_pass
networks:
- dev
command: '--path=`/var/www/html/WP-Site/`'
volumes:
- /WORK/:/var/www/html/
- /MYSQL/:/var/lib/mysql
working_dir: /var/www/html/
container_name: wpcli
networks:
dev:
NGINX配置是这样的
FROM php:7.2-fpm-alpine
# docker-entrypoint.sh dependencies
RUN apk add --no-cache \
# in theory, docker-entrypoint.sh is POSIX-compliant, but priority is a working, consistent image
bash \
# BusyBox sed is not sufficient for some of our sed expressions
sed
# https://github.com/docker-library/wordpress/blob/master/php7.3/fpm-alpine/Dockerfile
# install the PHP extensions we need
RUN set -ex; \
\
apk add --no-cache --virtual .build-deps \
libjpeg-turbo-dev \
libpng-dev \
libzip-dev \
; \
\
docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr; \
docker-php-ext-install gd mysqli opcache zip; \
\
runDeps="$( \
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
)"; \
apk add --virtual .wordpress-phpexts-rundeps $runDeps; \
apk del .build-deps
除WP-CLI之外的所有服务均正常工作。我的文件夹结构是这样的,在主WORK
文件夹下我有子文件夹,每个子文件夹中都有一个项目
这样的项目可以是WordPress,但也可以使用另一个CMS,或者只是小型静态站点
在http://localhost/
我看到了包含所有子文件夹的工作
文件夹的概述。点击任何项目文件夹,例如WP站点
,将引导我进入例如http://localhost/WP-Site/
。在那里,我有一个可以正常工作的WordPress安装,它可以很好地连接到PHP和MYSQL服务
但是,当尝试使用WP-CLI时,它会告诉我找不到工作的WordPress安装,当我在服务中传递命令并为其提供我拥有的WordPress项目之一的路径时,它将在没有错误消息的情况下退出
我真的需要WordPress映像才能使用WP-CLI映像吗。在WP-CLI服务中,我还提供了与MYSQL服务相同的环境变量,以便WP-CLI可以知道连接到何处
如果有任何方法可以运行WP-CLI容器并将其放在主WORK
文件夹下,那么对于我可能制作的所有项目,这将是非常好的
我本想把所有的东西都安装到一个图像中,但这样做违背了Docker的目的,即能够将东西分开并交换。所以我希望能够制作一个WP-CLI容器,它确实能够连接到我的PHP和MYSQL容器
upstream php {
server php:9000;
}
server {
listen 80;
server_name localhost;
## Your only path reference.
root /var/www/html;
## This should be in your http block and if it is, it's not needed here.
index index.php index.html index.htm;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location / {
# https://nginxlibrary.com/enable-directory-listing/
autoindex on;
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass php;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}