skip to Main Content

Can’t run apache2 in Docker container. I’m getting this message:

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

This is my docker-compose.yml:


version: "3"


services:
  site:
    build:
      context: .
      dockerfile: ./Dockerfile
    container_name: site
    ports:
      - "8080:80"
    volumes:
      - ./src:/var/www/html:delegated
    depends_on:
      - mysql
    networks:
      - laravel

  mysql:
    image: mysql:5.7.29
    container_name: mysql
    restart: unless-stopped
    tty: true
    ports:
      - "3306:3306"
    volumes:
      - ./mysql:/var/lib/mysql
    environment:
      MYSQL_DATABASE: homestead
      MYSQL_USER: homestead
      MYSQL_PASSWORD: secret
      MYSQL_ROOT_PASSWORD: secret
      SERVICE_TAGS: dev
      SERVICE_NAME: mysql
    networks:
      - laravel


networks:
  laravel:

Dockerfile:


FROM php:7.3-apache

RUN apt-get update && apt-get install -y wget zip

RUN docker-php-ext-install pdo_mysql mbstring

RUN wget https://getcomposer.org/installer -O - -q 
    | php -- --install-dir=/bin --filename=composer --quiet


RUN groupadd --gid 1000 www 
  && useradd --uid 1000 --gid www --shell /bin/bash --create-home www

USER www

WORKDIR /var/www/html

So, I want to work in container ‘site’ under non-root user, but apache2 does not start without root

2

Answers


  1. Chosen as BEST ANSWER

    The solution: add user: root to site container:

    ....
    
    site:
        build:
          context: .
          dockerfile: ./Dockerfile
        container_name: site
        user: root
        ports:
          - "8080:80"
        volumes:
          - ./src:/var/www/html:delegated
    
    ....
    

  2. Form apache documentation – How Apache Starts

    If the Listen specified in the configuration file is default of 80 (or any other port below 1024), then it is necessary to have root privileges in order to start apache, so that it can bind to this privileged port. Once the server has started and performed a few preliminary activities such as opening its log files, it will launch several child processes which do the work of listening for and answering requests from clients. The main httpd process continues to run as the root user, but the child processes run as a less privileged user.

    In my case I have:

    • in ports.conf
    Listen 8888
    
    • in Dockerfile
    FROM php:7.4-apache
    ...
    COPY ports.conf /etc/apache2/ports.conf
    ...
    

    and in docker-compose.yml

    ...
    ports:
      - 8080:8888 (or whatever port you have in Listen directive)
    ...
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search