【发布时间】:2017-02-02 08:05:13
【问题描述】:
我将 3 个单独的容器链接在一起:
我的目标是在将源代码复制到 nginx 容器之前运行 wp-cli 安装。
问题:
- 尝试从 Dockerfile(my-nginx 映像)运行 wp-cli 的安装脚本工作正常,但是当我尝试运行任何 wp-cli 命令时,它返回错误:
env: can't execute 'php': No such file or directory - wp-cli 安装脚本(具有正确的依赖项)也适用于 dockerfile.php-fpm(my-php 映像),它也会返回错误:
Error: YIKES! It looks like you're running this as root. You probably meant to run this as the user that your WordPress install exists under.并让我使用标志运行此命令 - -allow-root,在这种情况下这很糟糕,因为我想使用 wp 用户权限。或以其他用户身份运行此命令。
核心配置
docker-compose.yml:
version: '2'
services:
my-nginx:
build: .
volumes:
- .:/var/www/html
ports:
- "8080:80"
links:
- my-php
- my-mysql
my-php:
build:
context: .
dockerfile: Dockerfile.php-fpm
volumes:
- .:/var/www/html
ports:
- "9000:9000"
my-mysql:
image: mariadb:5.5
volumes:
- /var/lib/mysql
nginx.conf:
server {
server_name _;
listen 80 default_server;
root /var/www/html;
index index.php index.html;
access_log /dev/stdout;
error_log /dev/stdout info;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ .php$ {
include fastcgi_params;
fastcgi_pass my-php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
wp-cli 集成克隆自:https://github.com/conetix/docker-wordpress-wp-cli
选项 1
Dockerfile:
FROM nginx:1.10-alpine
# add root dir
RUN mkdir -p /var/www/html
WORKDIR /var/www/html
ENV WP_ROOT /var/www/html
# Install requirements for wp-cli support
RUN apk update \
&& apk add less mysql-client sudo curl
# copy nginx configuration
COPY nginx.conf /etc/nginx/conf.d/default.conf
# Add WP-CLI
RUN curl -o /bin/wp-cli.phar https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
COPY wp-su.sh /bin/wp
RUN chmod +x /bin/wp-cli.phar \
&& sudo mv /bin/wp-cli.phar /usr/local/bin/wp
RUN wp core download --allow-root
# copy all files for current dir (should be theme or plugin folder)
COPY . ./
Dockergile.php-fpm
FROM php:7.0.6-fpm-alpine
VOLUME /var/www/html
RUN docker-php-ext-install -j $(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) iconv gd mbstring fileinfo curl xmlreader xmlwriter mysqli
选项 2
Dockerfile:
FROM nginx:1.10-alpine
# add root dir
RUN mkdir -p /var/www/html
WORKDIR /var/www/html
RUN apk update \
&& apk add less mysql-client sudo
# copy nginx configuration
COPY nginx.conf /etc/nginx/conf.d/default.conf
# copy all files for current dir (should be theme or plugin folder)
COPY . ./
Dockergile.php-fpm
FROM php:7.0.6-fpm-alpine
VOLUME /var/www/html
RUN docker-php-ext-install -j $(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) iconv gd mbstring fileinfo curl xmlreader xmlwriter mysqli
# Install requirements for wp-cli support
RUN apk update \
&& apk add curl sudo less
ENV WP_ROOT /var/www/html
# Add WP-CLI
RUN curl -o /bin/wp-cli.phar https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
COPY wp-su.sh /bin/wp
RUN chmod +x /bin/wp-cli.phar \
&& sudo mv /bin/wp-cli.phar /usr/local/bin/wp
RUN wp core download
一般问题:
- 在 docker 中用户权限的最佳做法是什么?
- 来自https://github.com/conetix/docker-wordpress-wp-cli/blob/master/wp-su.sh 的wp-cli 集成使用www-data 用户-我应该将此用户添加到我的docker,如果是的话-添加到哪一个? ngnix 或 php-fpm 以及为什么。
- 从 php-fpm 容器 appaers 运行 wp donlowd 核心,就像它下载文件一样,但是当我尝试在其运行时执行时,这些文件都不会显示在 /var/www/html 中。是否有某种方法可以订购图像文件挂载?
- 如果我卷,为什么'php' 不可用来自 my-nginx 的命令
我的 PHP 图像?我还必须在这张图片上安装 php 吗?
【问题讨论】:
标签: wordpress docker docker-compose