Apache2 在 docker 容器上返回“APACHE_RUN_DIR”错误

Apache2 在 docker 容器上返回“APACHE_RUN_DIR”错误

当尝试在 docker 容器上启动 roundcube 邮件服务器时,出现 apache 错误:

AH00111: Config variable ${APACHE_RUN_DIR} is not defined
apache2: Syntax error on line 80 of /etc/apache2/apache2.conf:
DefaultRuntimeDir must be a valid directory, absolute or relative to 
ServerRoot

即使我在 dockerfile 中声明了所有环境变量,例如:

#FROM armv7/armhf-debian
FROM debian

RUN apt-get update -y && apt-get install sudo -y
RUN sudo apt-get install nano

# install exim,d ovecot, fetchmail, roundcoube
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y exim4 sudo wget ca-certificates
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y dovecot-imapd
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y fetchmail procmail
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y apache2 php5.* php5.*-mysql

#add
RUN sudo mkdir -p /etc/php5/apache2/

# add www-data to sudoers
RUN echo "www-data ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

# removing std. html site
RUN sudo rm /var/www/html/index.html

# downloading roundcube
RUN wget https://github.com/roundcube/roundcubemail/releases/download/1.2.3/roundcubemail-1.2.3-complete.tar.gz
RUN tar xvf roundcubemail-1.2.3-complete.tar.gz
RUN cp -rf roundcubemail-1.2.3/. /var/www/html/
RUN chown -R www-data:www-data /var/www/html/
RUN echo "MAIN_TLS_ENABLE = 1" >> /etc/exim4/exim4.conf.localmacros

# setting date.timezone
RUN echo 'date.timezone = "Europe/Berlin"' >> /etc/php5/apache2/php.ini

# enable fetchmail as daemon
RUN echo "START_DAEMON=yes" >> /etc/default/fetchmail

# let dovecot listen on ipv6
RUN echo "listen = *" >> /etc/dovecot/dovecot.conf

VOLUME ["/var/log/exim4"]

ADD ./scripts /scripts

# clean for smaller image
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# entrypoint
#ENTRYPOINT ["exim"]
ENTRYPOINT /bin/bash /scripts/init.sh
#CMD [/scripts/init.sh]

我用 init.sh 文件启动它,如下所示

我还检查了 evvars 和 direcories 是否存在于 docker 容器中。 RUN_DIR 已设置,并且 /var/run/apache2 也存在。其中是带有 id 的 apache2.pid 设置。

当打开本地主机地址时,会显示纯 php 代码。

答案1

  • 从 docker 文件中删除 apache 变量
  • 代替init.sh

    #!/bin/bash
    
    # define path to custom docker environment
    DOCKER_ENVVARS=/etc/apache2/docker_envvars
    
    # write variables to DOCKER_ENVVARS
    cat << EOF > "$DOCKER_ENVVARS"
    export APACHE_RUN_USER=www-data
    export APACHE_RUN_GROUP=www-data
    export APACHE_LOG_DIR=/var/log/apache2
    export APACHE_LOCK_DIR=/var/lock/apache2
    export APACHE_PID_FILE=/var/run/apache2.pid
    export APACHE_RUN_DIR=/var/run/apache2
    EOF
    
    # source environment variables to get APACHE_PID_FILE
    . "$DOCKER_ENVVARS"
    
    # only delete pidfile if APACHE_PID_FILE is defined
    if [ -n "$APACHE_PID_FILE" ]; then
       rm -f "$APACHE_PID_FILE"
    fi
    
    # start other services
    service exim4 start
    service dovecot start
    service fetchmail start
    
    # line copied from /etc/init.d/apache2
    ENV="env -i LANG=C PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
    
    # use apache2ctl instead of /usr/sbin/apache2
    $ENV APACHE_ENVVARS="$DOCKER_ENVVARS" apache2ctl -DFOREGROUND
    

相关内容