如何在docker-compose构建的LEMP堆栈中插入dockerised cron进程?

时间:2016-01-17 17:57:23

标签: php nginx docker cron docker-compose

我有一个由此docker-compose文件构建的LEMP堆栈:

cadvisor:
  image: google/cadvisor:latest
  container_name: lemp_cadvisor
  ports:
    - "8080:8080"
  volumes:
    - "/:/rootfs:ro"
    - "/var/run:/var/run:rw"
    - "/sys:/sys:ro"
    - "/var/lib/docker/:/var/lib/docker:ro"
base:
  build: ./base
  container_name: lemp_base
  volumes:
    - /home/core/server-lemp/www/:/var/www/:rw
phpmyadmin:
  build: ./phpmyadmin
  container_name: lemp_phpmyadmin
  links:
    - base
  volumes:
    - /var/www/phpmyadmin
    - ./phpmyadmin/var/www/phpmyadmin/config.inc.php:/var/www/phpmyadmin/config.inc.php:rw
mariadb:
  build: ./mariadb
  container_name: lemp_mariadb
  environment:
    - MYSQL_ROOT_PASSWORD=pwd
  links:
    - base
  volumes:
    - /var/run/mysqld
    - /home/core/server-lemp/mariadb/:/var/lib/mysql/:rw
    - ./mariadb/etc/mysql/my.cnf:/etc/mysql/my.cnf:ro
ffmpeg:
  build: ./ffmpeg
  container_name: lemp_ffmpeg
  links:
    - base
  volumes:
    - /usr/ffmpeg
cron:
  build: ./cron
  container_name: lemp_cron
  links:
    - base
  volumes:
    - /etc/cron.weekly
    - /etc/cron.d
    - /etc/cron.hourly
    - /etc/cron.daily
    - /etc/cron.monthly
php:
  build: ./php
  container_name: lemp_php
  links:
    - base
  volumes:
    - /var/run/php-fpm
    - ./php/usr/local/php7/etc/php-fpm.conf:/usr/local/php7/etc/php-fpm.conf:ro
    - ./php/usr/local/php7/etc/php.ini:/usr/local/php7/etc/php.ini:ro
    - ./php/usr/local/php7/etc/php-fpm.d/www.conf:/usr/local/php7/etc/php-fpm.d/www.conf:ro
  volumes_from:
    - base
    - phpmyadmin
    - mariadb
    - ffmpeg
    - cron
nginx:
  build: ./nginx
  container_name: lemp_nginx
  links:
    - base
  ports:
    - "80:80"
    - "443:443"
  volumes:
    - /var/cache/nginx
    - ./nginx/etc/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
  volumes_from:
    - php

我的./cron/Dockerfile看起来像这样:

# Lanti/lempCron
#
# VERSION               1.0.0

FROM lemp_base:latest
MAINTAINER XY <info@domain.com>
LABEL Description="Cron" Vendor="XY" Version="1.0"

RUN apt-get -y update && apt-get -y dist-upgrade \
    && apt-get -y install \
        cron

RUN rm -rf /var/lib/apt/lists/*

CMD ["cron", "-f"]

在Wordpress安装中,我使用WP Crontrol插件检查正在运行的cron作业时,收到以下错误消息:

There was a problem spawning a call to the WP-Cron system on your site.
This means WP-Cron events on your site may not work. The problem was:
Failed to connect to 127.0.0.1 port 80: Connection refused

我假设由于导致此错误的相同错误,Nginx-helper插件中的Cache Purge选项也无效。

1 个答案:

答案 0 :(得分:0)

Wordpress可能正在您的“php”中运行。容器,&#34; wp-cron&#34;功能可能在那里工作。虽然它是&#34; cron-like&#34;,但它实际上是Wordpress的一部分。

您已为您的`php&#39;定义了ports。容器,因此您似乎需要更新Docker networking,以便wp-contain可以访问正确主机上的端口80.