Docker:(13)权限被拒绝:AH00072:make_sock:无法绑定到地址 0.0.0.0:80

Docker: (13)Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:80

无法在 Docker 容器中 运行 apache2。我收到这条消息:

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

这是我的 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:

Docker文件:


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

所以,我想在非 root 用户下的容器 'site' 中工作,但是 apache2 没有 root 就无法启动

解决方法:添加用户:root站点容器:

....

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

....