Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

228
Vistas
Docker Laravel Run Port Expose Permission denied

We want to dockerize a Laravel app ready to deploy on AWS ECR/ECS. We made some test but we are having some issues with the apache configuration.

We hace the next Dockerfile:

FROM php:7.4-apache

WORKDIR /var/www/html

# Copy composer.lock and composer.json
COPY composer.lock* composer.json* /var/www/html/

# install all the dependencies and enable PHP modules
RUN apt-get update && apt-get upgrade -y && apt-get install -y \
      procps \
      nano \
      git \
      unzip \
      libicu-dev \
      zlib1g-dev \
      libxml2 \
      libxml2-dev \
      libreadline-dev \
      supervisor \
      cron \
      libzip-dev \
      libpng-dev  \
    && docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd \
    && docker-php-ext-configure intl \
    && docker-php-ext-install \
      pdo_mysql \
      sockets \
      intl \
      opcache \
      zip \
      gd \
    && rm -rf /tmp/* \
    && rm -rf /var/list/apt/* \
    && rm -rf /var/lib/apt/lists/* \
    && apt-get clean

# disable default site and delete all default files inside APP_HOME
RUN a2dissite 000-default.conf

# put apache and php config for Laravel, enable sites
COPY ./docker/general/laravel.conf /etc/apache2/sites-available/laravel.conf
RUN a2ensite laravel.conf

# enable apache modules
RUN a2enmod rewrite
RUN a2enmod ssl

# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN curl -sL https://deb.nodesource.com/setup_12.x -o nodesource_setup.sh
RUN bash nodesource_setup.sh

# NPM for frontend builds
RUN apt-get install nodejs

RUN rm nodesource_setup.sh

# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www

# Copy existing application directory contents
COPY ./ /var/www/html

# Copy existing application directory permissions
COPY --chown=www:www . /var/www/html

# Change current user to www
USER www

# Expose port 9000 and start php-fpm server
EXPOSE 80

And docker-compose.yml:

version: '3'

services:
    laravel: &laravel-template
      image: laravel:latest
      build:
        context: .
        args:
          - "BUILD_ARGUMENT_ENV=dev"
          - "BUILD_ARGUMENT_DEBUG_ENABLED=false"
        dockerfile: ./Dockerfile
      container_name: laravel
      expose:
        - 80
      ports:
        - 8080:80
      volumes:
        - .:/var/www/html

When we deploy the application it doesn't show any error, but we believe is because of the port expose, if we try to run it locally with docker run -it -p 8080:80 tok , it shows:

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
(13)Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs

Are we missing something?

9 months ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I spent a long time debugging the ServerName message, only to find out it was a red herring. It's a warning and can be safely ignored. We resolved the issue by adding USER root to the end of the Dockerfile, which solves the permissions error.

9 months ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.