在Heroku上使用Apache部署停靠的Laravel应用程序

在Heroku上使用Apache部署停靠的Laravel应用程序,laravel,apache,docker,heroku,port,Laravel,Apache,Docker,Heroku,Port,我正在尝试在Heroku上使用Docker部署Laravel 5.5应用程序。我遇到了一个问题,Heroku动态地分配$PORT值,但我不知道在哪里告诉Apache使用$PORT而不是端口80。是否有其他人成功地将使用Apache in Docker的应用程序部署到Heroku,并使用$PORT规范 具体来说,这是我跟踪Heroku日志时遇到的错误: 2019-01-31T14:01:17.605297+00:00 app[web.1]: (13)Permission denied: AH000

我正在尝试在Heroku上使用Docker部署Laravel 5.5应用程序。我遇到了一个问题,Heroku动态地分配$PORT值,但我不知道在哪里告诉Apache使用$PORT而不是端口80。是否有其他人成功地将使用Apache in Docker的应用程序部署到Heroku,并使用$PORT规范

具体来说,这是我跟踪Heroku日志时遇到的错误:

2019-01-31T14:01:17.605297+00:00 app[web.1]: (13)Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:80
我理解这意味着容器试图侦听端口80,但主机使用$Port而不是80

这是我的Dockerfile:

FROM php:7.1.5-apache

#install all the system dependencies and enable PHP modules 
RUN apt-get update && apt-get install -y \
  libicu-dev \
  libpq-dev \
  libmcrypt-dev \
  git \
  zip \
  unzip \
  && rm -r /var/lib/apt/lists/* \
  && docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd \
  && docker-php-ext-install \
  intl \
  mbstring \
  mcrypt \
  pcntl \
  pdo_mysql \
  pdo_pgsql \
  pgsql \
  zip \
  opcache

ENV PHPREDIS_VERSION 3.0.0

RUN mkdir -p /usr/src/php/ext/redis \
  && curl -L https://github.com/phpredis/phpredis/archive/$PHPREDIS_VERSION.tar.gz | tar xvz -C /usr/src/php/ext/redis --strip 1 \
  && echo 'redis' >> /usr/src/php-available-exts \
  && docker-php-ext-install redis

#install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer

#set our application folder as an environment variable
ENV APP_HOME /var/www/html

#change uid and gid of apache to docker user uid/gid
RUN usermod -u 1000 www-data && groupmod -g 1000 www-data

#change the web_root to laravel /var/www/html/public folder
RUN sed -i -e "s/html/html\/public/g" /etc/apache2/sites-enabled/000-default.conf

# enable apache module rewrite
RUN a2enmod rewrite

#copy source files and run composer
COPY . $APP_HOME

# install all PHP dependencies
RUN composer install --no-interaction

#change ownership of our applications
RUN chown -R www-data:www-data $APP_HOME
这是我的Heroku文件:

web: vendor/bin/heroku-php-apache2 public/
这是我的heroku.yml:

build:
  docker:
    web: Dockerfile
谢谢

明白了

使用,我发现我可以在Dockerfile的末尾插入
CMD
语句,以
sed
在运行时将apache配置文件中的端口替换为神奇的
$PORT
环境变量

新的Dockerfile如下:

#start with our base image (the foundation) - version 7.1.5
FROM php:7.1.5-apache

#install all the system dependencies and enable PHP modules 
RUN apt-get update && apt-get install -y \
  libicu-dev \
  libpq-dev \
  libmcrypt-dev \
  git \
  zip \
  unzip \
  && rm -r /var/lib/apt/lists/* \
  && docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd \
  && docker-php-ext-install \
  intl \
  mbstring \
  mcrypt \
  pcntl \
  pdo_mysql \
  pdo_pgsql \
  pgsql \
  zip \
  opcache

ENV PHPREDIS_VERSION 3.0.0

RUN mkdir -p /usr/src/php/ext/redis \
  && curl -L https://github.com/phpredis/phpredis/archive/$PHPREDIS_VERSION.tar.gz | tar xvz -C /usr/src/php/ext/redis --strip 1 \
  && echo 'redis' >> /usr/src/php-available-exts \
  && docker-php-ext-install redis

#install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer

#set our application folder as an environment variable
ENV APP_HOME /var/www/html

#change uid and gid of apache to docker user uid/gid
RUN usermod -u 1000 www-data && groupmod -g 1000 www-data

#change the web_root to laravel /var/www/html/public folder
RUN sed -i -e "s/html/html\/public/g" /etc/apache2/sites-enabled/000-default.conf

# enable apache module rewrite
RUN a2enmod rewrite

#copy source files and run composer
COPY . $APP_HOME

# install all PHP dependencies
RUN composer install --no-interaction

#change ownership of our applications
RUN chown -R www-data:www-data $APP_HOME

#update apache port at runtime for Heroku
ENTRYPOINT []
CMD sed -i "s/80/$PORT/g" /etc/apache2/sites-enabled/000-default.conf /etc/apache2/ports.conf && docker-php-entrypoint apache2-foreground

您使用什么命令和参数来启动容器?码头集装箱的公共港口是Heroku港口的所在地。Dockerfile中定义的内部端口不相关。@Namoshek据我所知,Heroku使用Procfile中的命令来运行容器。我已经用我的heroku.yml更新了我的帖子,表明我没有使用任何运行配置,根据第一段的结尾,它应该默认为Procfile