我有这个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
volumes_from:
- base
volumes:
- /var/www/phpmyadmin
- ./phpmyadmin/var/www/phpmyadmin/config.inc.php:/var/www/phpmyadmin/config.inc.php:rw
ffmpeg:
build: ./ffmpeg
container_name: lemp_ffmpeg
volumes_from:
- phpmyadmin
volumes:
- /usr/ffmpeg
mariadb:
build: ./mariadb
container_name: lemp_mariadb
environment:
- MYSQL_ROOT_PASSWORD=your-pwd
volumes_from:
- ffmpeg
volumes:
- /var/run/mysqld
- /home/core/server-lemp/mariadb:/var/lib/mysql:rw
- ./mariadb/etc/mysql/my.cnf:/etc/mysql/my.cnf:ro
php:
build: ./php
container_name: lemp_php
volumes_from:
- mariadb
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
- ./php/etc/supervisor/conf.d/supervisord.conf:/etc/supervisor/conf.d/supervisord.conf:ro
- ./php/etc/cron.d:/etc/cron.d:ro
nginx:
build: ./nginx
container_name: lemp_nginx
net: "host"
ports:
- "80:80"
- "443:443"
volumes_from:
- php
volumes:
- /var/cache/nginx
- ./nginx/etc/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
当我启动此堆栈时,我的主机上的/home/core/server-lemp/www
将删除每个文件,该文件将共享到/var/www
。
过去没有发生这种情况,新命令在nginx下只有net: "host"
。
这就是我的docker-compose日志的样子:
Jan 18 22:10:14 core-1 docker-compose[11563]: Going to remove lemp_nginx, lemp_php, lemp_mariadb, lemp_ffmpeg, lemp_phpmyadmin, lemp_base, lemp_cadvisor
Jan 18 22:10:14 core-1 docker-compose[11563]: Removing lemp_nginx ...
Jan 18 22:10:14 core-1 docker-compose[11563]: Removing lemp_php ...
Jan 18 22:10:14 core-1 docker-compose[11563]: Removing lemp_mariadb ...
Jan 18 22:10:14 core-1 docker-compose[11563]: Removing lemp_ffmpeg ...
Jan 18 22:10:14 core-1 docker-compose[11563]: Removing lemp_phpmyadmin ...
Jan 18 22:10:14 core-1 docker-compose[11563]: Removing lemp_base ...
Jan 18 22:10:14 core-1 docker-compose[11563]: Removing lemp_cadvisor ...
--> The deletion happening somewhere here
Jan 18 22:10:16 core-1 docker-compose[11563]: [303B blob data]
Jan 18 22:10:16 core-1 docker-compose[11563]: ERROR: for lemp_mariadb Driver overlay failed to remove root filesystem 3f35133e0814235cc4b9814606798f50d22e472d415ca814beb3443df8b89e3c: remove /var/lib/docker/overlay/3f35133e0814235cc4b9814606798f50d22e472d415ca814beb3443df8b89e3c/merged/var/www/phpmyadmin: device or resource busy
Jan 18 22:10:17 core-1 docker-compose[11579]: Creating lemp_cadvisor
更新
这是我的基础Dockerfile:
# Lanti/lempBase
#
# VERSION 1.0.0
FROM debian:latest
MAINTAINER Istvan Lantos <info@lantosistvan.com>
LABEL Description="This image is the base of the other app images in this project" Vendor="Istvan Lantos" Version="1.0"
ENV TERM linux
ENV DEBIAN_FRONTEND noninteractive
RUN ln -sf /bin/bash /bin/sh && ln -sf /bin/bash /bin/sh.distrib
RUN echo -e "\
deb http://httpredir.debian.org/debian stable main contrib non-free\n\
deb-src http://httpredir.debian.org/debian stable main contrib non-free\n\
deb http://security.debian.org stable/updates main contrib non-free\n\
deb-src http://security.debian.org stable/updates main contrib non-free\n\
deb http://httpredir.debian.org/debian stable-updates main contrib non-free\n\
deb-src http://httpredir.debian.org/debian stable-updates main contrib non-free" > /etc/apt/sources.list
RUN apt-get -y update && apt-get -y dist-upgrade
### Start of optimizations
# https://easyengine.io/tutorials/linux/increase-open-files-limit/
RUN echo -e "\n\
* hard nofile 500000\n\
* soft nofile 500000\n\
root hard nofile 500000\n\
root soft nofile 500000" >> /etc/security/limits.conf \
&& echo -e "session required pam_limits.so" >> /etc/pam.d/common-session \
&& echo -e "fs.file-max = 2097152" >> /etc/sysctl.conf
### End of optimizations
### Start of Nginx WEBSERVER setup
RUN mkdir -p /var/www
# Modify www-data user and set UID, GID to 500
# https://muffinresearch.co.uk/linux-changing-uids-and-gids-for-user/
RUN groupmod -g 500 www-data \
&& usermod -u 500 www-data \
#&& `find / -user 33 -exec chown -h 500 {} \;` \
#&& `find / -group 33 -exec chgrp -h 500 {} \;` \
&& usermod -g 500 www-data \
&& chown -R www-data:www-data /var/www \
&& chmod g+s /var/www
### End of Nginx WEBSERVER setup
RUN mkdir -p /root/lemp_base_volume
RUN rm -rf /var/lib/apt/lists/*
CMD ["tail", "-f", "/dev/null"]
更新2:
似乎你无法以菊花链形式连接容器来创建构建订单,因为mariadb
发生的事情会导致删除所有静态网络服务器文件。
现在这是我的docker-compose文件,我回到我的旧解决方案,我曾经将所有内容链接到基础,而不是将它们的卷分享到php,而不是DAISY CHAINING他们:
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:
- /root/lemp_base_volume
www:
image: lemp_base
container_name: lemp_www
volumes_from:
- base
volumes:
- /home/core/server-lemp/www:/var/www:rw
phpmyadmin:
build: ./phpmyadmin
container_name: lemp_phpmyadmin
volumes_from:
- base
volumes:
- /var/www/phpmyadmin
- ./phpmyadmin/var/www/phpmyadmin/config.inc.php:/var/www/phpmyadmin/config.inc.php:rw
ffmpeg:
build: ./ffmpeg
container_name: lemp_ffmpeg
volumes_from:
- base
volumes:
- /usr/ffmpeg
mariadb:
build: ./mariadb
container_name: lemp_mariadb
environment:
- MYSQL_ROOT_PASSWORD=your-db-pwd
volumes_from:
- base
volumes:
- /var/run/mysqld
- /home/core/server-lemp/mariadb:/var/lib/mysql:rw
- ./mariadb/etc/mysql/my.cnf:/etc/mysql/my.cnf:ro
php:
build: ./php
container_name: lemp_php
volumes_from:
- www
- phpmyadmin
- ffmpeg
- mariadb
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
- ./php/etc/cron.d:/etc/cron.d:ro
nginx:
build: ./nginx
container_name: lemp_nginx
ports:
- "80:80"
- "443:443"
volumes_from:
- php
volumes:
- /var/cache/nginx
- ./nginx/etc/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
我创建了一个名为www
的新容器,它是从主机共享的静态Web服务器文件的基本映像。 base
现在只需要因为所有其他图像都是从这张图片构建的。
就像在我使用link
创建网络的旧解决方案中一样,每个共享卷都会在php
和php
的卷中共享nginx
,这是最重要的。
所以:
links:
- base
变成了:
volumes_from:
- base
维护构建顺序并确保首先构建base
。
我使用docker-compose --x-networking --x-network-driver=bridge up
为此堆栈创建了桥接网络。
但看起来cron的工作再次无效。
UPDATE3:
这是我用rsyslog获得的:
root@0687540163a3:/var/log# cat syslog
Jan 22 14:45:04 0687540163a3 rsyslogd: [origin software="rsyslogd" swVersion="8.4.2" x-pid="13" x-info="http://www.rsyslog.com"] start
Jan 22 14:45:04 0687540163a3 rsyslogd: imklog: cannot open kernel log(/proc/kmsg): Operation not permitted.
Jan 22 14:45:04 0687540163a3 rsyslogd-2145: activation of module imklog failed [try http://www.rsyslog.com/e/2145 ]
Jan 22 14:45:04 0687540163a3 cron[22]: (CRON) INFO (pidfile fd = 3)
Jan 22 14:45:04 0687540163a3 cron[23]: (CRON) STARTUP (fork ok)
Jan 22 14:45:04 0687540163a3 cron[23]: (*system*) NUMBER OF HARD LINKS > 1 (/etc/crontab)
Jan 22 14:45:04 0687540163a3 cron[23]: (*system*wpcron) NUMBER OF HARD LINKS > 1 (/etc/cron.d/wpcron)
Jan 22 14:45:04 0687540163a3 cron[23]: (*) ORPHAN (no passwd entry)
Jan 22 14:45:04 0687540163a3 cron[23]: (CRON) INFO (Running @reboot jobs)
Jan 22 14:46:01 0687540163a3 cron[23]: (*system*) NUMBER OF HARD LINKS > 1 (/etc/crontab)
Jan 22 14:46:01 0687540163a3 cron[23]: (*system*wpcron) NUMBER OF HARD LINKS > 1 (/etc/cron.d/wpcron)
Jan 22 14:46:01 0687540163a3 cron[23]: (*) ORPHAN (no passwd entry)
这就是我的wpcron文件:
*/1 * * * * www-data php /var/www/domain.com/wp-cron.php >> /var/log/wp-cron.log 2>&1
在前5分钟后,/var/log/wp-cron.log
仍未创建。
答案 0 :(得分:2)
我遇到了同样的问题。我认为lemp_mariadb
容器存在一些问题。
解决这个问题。您应该尝试以下步骤:
获取lemp_mariadb
容器ID:
docker ps -a
如果您看到lemp_mariadb
状态为Dead
。你应该去/var/lib/docker/containers
。您找到与lemp_mariadb容器ID具有相同名称的目录并将其删除
rm -rf /var/lib/docker/containers/lemp_mariadb_container_id