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設定があります。
localhostアドレスを開くと、純粋な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