Docker入口点为什么我得到错误的参数

时间:2016-11-17 21:24:00

标签: bash docker moodle dockerfile

我正在制作一个包含此Dockerfile的自定义docker镜像

# Dockerfile for moodle instance.
# Forked from Jonathan Hardison's <jmh@jonathanhardison.com> docker version. https://github.com/jmhardison/docker-moodle

FROM  php:7.0-apache
MAINTAINER Dimitrios Desyllas <ddesyllas@freemail.gr>
#Original Maintainer Jon Auer <jda@coldshore.com>

VOLUME ["/var/moodledata"]
EXPOSE 80


# Let the container know that there is no tty
ENV DEBIAN_FRONTEND noninteractive

# Moodle Info
ENV MOODLE_URL http://0.0.0.0
ENV MOODLE_ADMIN admin
ENV MOODLE_ADMIN_PASSWORD Admin~1234
ENV MOODLE_ADMIN_EMAIL admin@example.com

#DATABASE SETTINGS

#Supported 'pgsql', 'mariadb', 'mysqli',
ENV MOODLE_DB_TYPE 'mysqli'
ENV MOODLE_DB_HOST ''
ENV MOODLE_DB_USER ''
ENV MOODLE_DB_PASSWORD ''
ENV MOODLE_DB_NAME 'moodle'
ENV MOODLE_DB_PORT '3306'


RUN echo "Installing php and external tools"
RUN apt-get update && \
        apt-get -f -y install mysql-client pwgen aspell unzip wget libxmlrpc-c++8-dev libxml2-dev libpng-dev libicu-dev libmcrypt-dev &&\
        docker-php-ext-install mysqli && \
        docker-php-ext-install pdo pdo_mysql && \
        docker-php-ext-install xmlrpc && \
        docker-php-ext-install mbstring && \
        docker-php-ext-install zip && \
        docker-php-ext-install xml && \
        docker-php-ext-install intl && \
        docker-php-ext-install soap && \
        docker-php-ext-install mcrypt && \
        docker-php-ext-install gd && \
        echo "Installing moodle" && \
        wget https://download.moodle.org/download.php/direct/stable31/moodle-latest-31.tgz -O /tmp/moodle-latest-31.tgz  && \
        rm -rf /var/www/html/index.html && \
        tar -xvf /tmp/moodle-latest-31.tgz -C /tmp && \
        mv /tmp/moodle/* /var/www/html/

COPY moodle-config.php /var/www/html/config.php
COPY ./entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

# Cleanup
RUN apt-get clean autoclean && apt-get autoremove -y && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /var/lib/dpkg/* /var/lib/cache/* /var/lib/log/*

ENTRYPOINT /usr/local/bin/entrypoint.sh
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

但由于某些原因,在以下entrypoint.sh脚本中,我得到错误的参数给exec

#!/bin/bash

echo "Installing moodle"

echo "Fixing files and permissions"

chown -R www-data:www-data /var/www/html
find /var/www/html -iname "*.php" | xargs chmod +x

echo "placeholder" > /var/moodledata/placeholder
chown -R www-data:www-data /var/moodledata
chmod 777 /var/moodledata

echo "Setting up database"
: ${MOODLE_DB_TYPE:='mysqli'}

if [ "$MOODLE_DB_TYPE" = "mysqli" ] || [ "$MOODLE_DB_TYPE" = "mariadb" ]; then

  set ${MOODLE_DB_HOST:=$DB_PORT_3306_TCP_ADDR}

  echo "Waiting for mysql to connect.."
  while ! mysqladmin ping -h"$MOODLE_DB_HOST" --silent; do
      sleep 1
  done

  echo "Setting up the database connection info"
: ${MOODLE_DB_USER:=${DB_ENV_MYSQL_USER:-root}}
: ${MOODLE_DB_NAME:=${DB_ENV_MYSQL_DATABASE:-'moodle'}}
: ${MOODLE_DB_PORT:=${DB_PORT_3306_TCP_PORT}}

  if [ "$MOODLE_DB_USER" = 'root' ]; then
: ${MOODLE_DB_PASSWORD:=$DB_ENV_MYSQL_ROOT_PASSWORD}
  else
: ${MOODLE_DB_PASSWORD:=$DB_ENV_MYSQL_PASSWORD}
  fi

  if [ -z "$MOODLE_DB_PASSWORD" ]; then
    echo >&2 'error: missing required MOODLE_DB_PASSWORD environment variable'
    echo >&2 '  Did you forget to -e MOODLE_DB_PASSWORD=... ?'
    echo >&2
    exit 1
  fi

else
  echo >&2 "This database type is not supported"
  echo >&2 "Did you forget to -e MOODLE_DB_TYPE='mysqli' ^OR^ -e MOODLE_DB_TYPE='mariadb' ?"
  exit 1
fi

echo "Installing moodle"
php /var/www/html/admin/cli/install_database.php \
          --adminemail=${MOODLE_ADMIN_EMAIL} \
          --adminuser=${MOODLE_ADMIN} \
          --adminpass=${MOODLE_ADMIN_PASSWORD} \
          --agree-license

exec "$@"

但是在exec "$@"上,"$@"值获取了一个docker的ip而不是注释来启动apache /usr/sbin/apache2ctl -D FOREGROUND,我无法弄清楚为什么会发生这种情况。

原作是https://github.com/ellakcy/docker-moodle

1 个答案:

答案 0 :(得分:1)

从脚本中删除行set中的set ${MOODLE_DB_HOST:=$DB_PORT_3306_TCP_ADDR}

$ help set
set: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
    Set or unset values of shell options and positional parameters.