在Heroku上使用Apache部署Dockerized Laravel应用 [英] Deploy a Dockerized Laravel app using Apache on Heroku

查看:78
本文介绍了在Heroku上使用Apache部署Dockerized Laravel应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Heroku上使用Docker部署Laravel 5.5应用程序.我遇到的问题是Heroku虽然会动态分配$ PORT值,但我不知道该告诉Apache使用$ PORT而不是端口80.在Docker中使用Apache部署应用程序的人是否成功?到具有$ PORT规范的Heroku?

I'm trying to deploy a Laravel 5.5 app using Docker on Heroku. I'm coming up against the problem where Heroku dynamically assigns the $PORT value though, and I can't figure out where to tell Apache to use $PORT instead of port 80. Has anyone else had success deploying an app using Apache in Docker to Heroku with the $PORT specification?

具体来说,这是我在Heroku日志中出现的错误:

To be specific, this is the error I get tailing the Heroku logs:

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.

which I understand to mean that the container is trying to listen on Port 80, but the host is using $PORT instead of 80.

这是我的Dockerfile:

Here's my 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 Procfile:

And here's my Heroku Procfile:

web: vendor/bin/heroku-php-apache2 public/

这是我的heroku.yml:

And here's my heroku.yml:

build:
  docker:
    web: Dockerfile

谢谢!

推荐答案

知道了.

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

Using this SO post, I discovered I could insert a CMD statement at the end of my Dockerfile to sed replace the ports in my apache config files to the magical $PORT environment variable at run time.

下面的新Dockerfile:

New Dockerfile below:

#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上使用Apache部署Dockerized Laravel应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆