php - Docker-compose 构建内存不足
问题描述
我正在尝试为具有以下功能的旧版应用程序构建 php-apache 容器:
- 实际 git 控制的项目被挂载到容器中
- 容器以主机用户身份运行(使用 uid 和 gid)以克服权限问题
- 该项目几乎没有相互连接的站点,因此我们开放了一些端口,以便更轻松地从主机访问它们。
这是 docker-compose.yml 文件:
version: '3.7'
services:
db:
env_file:
- ./docker/docker.env
build:
context: .
dockerfile: ./docker/mysql/Dockerfile
network: host
user: '74:74'
ports:
- "3307:3306"
volumes:
- ./docker/mysql/db_data:/var/lib/mysql
restart: on-failure
php:
env_file:
- ./docker/docker.env
build:
args:
- USER_ID=${USER_ID}
- GROUP_ID=${GROUP_ID_WWW}
- USER=cakephp
- PWD=password
- HTTP_PROXY=${HTTP_PROXY}
- HTTPS_PROXY=${HTTPS_PROXY}
context: .
dockerfile: ./docker/php/Dockerfile
network: host
depends_on:
- db
ports:
- "9080:80"
- "9081:80"
- "9082:80"
- "9083:80"
volumes:
- ./bakery:/var/www/html
- ./bakery-assets:/var/www/assets
- ./bakery-live:/var/www/local-live
- ./bakery-preview:/var/www/local-preview
- ./docker/apache/vhosts:/etc/apache2/sites-enabled
- ./docker/php/tmp:/tmp/xdebug
restart: on-failure
networks:
hostnet:
external: true
name: host
这是 php 服务的 dockerfile:
FROM php:7.2-apache
ARG USER_ID=123456
ARG GROUP_ID=70
ARG USER=cakephp
ARG PWD=password
ARG HTTP_PROXY
ARG HTTPS_PROXY
ENV http_proxy=${HTTP_PROXY}
ENV https_proxy=${HTTPS_PROXY}
# creating user with host user UID and _www user GID
# www-data details on docker container: uid=33(www-data) gid=33(www-data) groups=33(www-data)
RUN groupadd -r --gid=70 apache
RUN useradd -Mr apache --uid=70 --gid=70
#RUN groupadd -r --gid=70 cakephp
RUN useradd -Mr cakephp --uid=123456 --gid=70
# we do not need home directory for the cakephp user (so using -M switch)
# using the -l log when the uid or gid is a large number. otherwise it ends up in error: write /var/log/lastlog: no space left on device
RUN useradd -M cakephp --uid=123456 --gid=70 --groups=sudo -l && echo "cakephp:password" | chpasswd
ENV APACHE_RUN_USER=cakephp
ENV APACHE_RUN_GROUP=apache
RUN if [ "${HTTP_PROXY}" != "" ]; then \
# needed as we're behind proxy
pear config-set http_proxy ${HTTP_PROXY} \
;fi
# RUN apt-get update && apt-get install apt-utils -y --no-install-recommends
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
g++ \
libicu-dev \
libcurl4-openssl-dev \
libldap2-dev \
libpng-dev \
libssl-dev \
libxml2-dev \
libzip-dev \
openssl \
pkg-config \
vim \
zip \
zlib1g-dev \
&& apt-get clean
# && apt-get clean \
# && rm -rf /var/lib/apt/lists/*
# COPY apache/conf/httpd.conf /etc/apache2/httpd.conf
# ENV APACHE_DOCUMENT_ROOT /path/to/new/root
# RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
# RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
# images ships with php.ini-development and php.ini-production config files
# use the default production configuration
#RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
RUN cp "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
RUN docker-php-ext-install \
curl \
gd \
intl \
mbstring \
mysqli \
opcache \
pdo \
sockets
#RUN docker-php-ext-configure bcmath --enable-bcmath
# && docker-php-ext-configure intl \
# && docker-php-ext-configure mbstring --enable-mbstring \
# Set timezone
RUN ln -snf "/usr/share/zoneinfo/${TIMEZONE}" /etc/localtime && echo "${TIMEZONE}" > /etc/timezone
RUN printf '[PHP]\ndate.timezone = "%s"\n', "${TIMEZONE}" > /usr/local/etc/php/conf.d/tzone.ini
RUN "date"
# enable bcmath
RUN docker-php-ext-configure bcmath --enable-bcmath \
&& docker-php-ext-install bcmath
# enable ldap
RUN docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu \
&& docker-php-ext-install ldap
# enable pdo mysql
RUN docker-php-ext-configure pdo_mysql --with-pdo-mysql \
&& docker-php-ext-install pdo_mysql
# enable zip
RUN docker-php-ext-configure zip --with-libzip \
&& docker-php-ext-install zip
# override with custom settings
# install xdebug
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug
# enable short tag. php ini is in /usr/local/etc/php directory.
# RUN sed -ri -e 's!/usr/local/etc/php/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
# RUN echo ${HTTP_PROXY}
# RUN curl -sS https://getcomposer.org/installer -x http://dev-server-proxy.cmc.local:3128 | php --install-dir=/usr/local/bin --filename=composer
#RUN curl -sS https://getcomposer.org/installer -x ${HTTP_PROXY} | php --install-dir=/usr/local/bin --filename=composer
# RUN composer --version
# RUN composer install
WORKDIR /var/www/html/httpdocs
# USER ${USER_ID}:${GROUP_ID}
# USER cakephp
ENV APACHE_RUN_DIR=/var/www/
ENV APACHE_LOG_DIR=/var/log/apache2/
CMD whoami
CMD id cakephp
尝试构建 php 服务时,空间不足,运行“docker system df”会返回如下输出:
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 14 0 5.236GB 5.236GB (100%)
Containers 1 0 295GB 295GB (100%)
Local Volumes 0 0 0B 0B
Build Cache 0 0 0B 0B
我不明白 php 容器构建过程为什么会占用 295GB 甚至更多。是我的 Docker 构建过程有问题还是 docker 有问题。
我尝试运行 'docker system prune' 和 'docker volume prune' 并重新启动 docker,但结果总是这样。
我很感激这方面的帮助。谢谢。
解决方案
推荐阅读
- flutter - 是否可以在飞镖中使用像 C++ 这样的模板参数?
- visual-studio - 当我只安装了 VS2019 时,我可以获得 Visual Studio 2015 命令提示符吗?
- javascript - React js google map @react-google-maps/api 添加标记 重新渲染太多。React 限制渲染次数以防止无限循环
- php - API无状态数据库访问性能
- excel - VBA 范围类失败
- reactjs - 在 React.js 中使用引导导航栏
- angular - 有没有办法以角度 8 的网格形式显示产品?例如具有 3 列和第 n 行的表格形式
- amazon-web-services - How to keep column names using AWS DMS with S3 as a target?
- angular - TypeError:无法读取未定义的属性“标题”-帮帮我:(
- selenium - 发送关于 testSuite 完成的 emailable.html testNG 报告总是发送旧报告