Search code examples
dockerbuildcontainers

Error during docker build PHP 8.1 on Ubuntu 20.04


I'm working on a Ubuntu Linux 20.04 Docker version is: Docker version 20.10.18, build b40c2f6

I have the following Dockerfile file

FROM ubuntu:20.04

LABEL maintainer="Taylor Otwell"

ARG WWWGROUP
ARG NODE_VERSION=16

WORKDIR /var/www/html

ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN apt-get update  \
    && apt-get install -y apt-transport-https
RUN apt-get install -y software-properties-common gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 \
    && mkdir -p ~/.gnupg \
    && chmod 600 ~/.gnupg \
    && echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf
RUN LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php \
    && apt-get update \
    && apt-get install -y php8.1-cli php8.1-dev \
       php8.1-pgsql php8.1-sqlite3 php8.1-gd \
       php8.1-curl \
       php8.1-imap php8.1-mysql php8.1-mbstring \
       php8.1-xml php8.1-zip php8.1-bcmath php8.1-soap \
       php8.1-intl php8.1-readline \
       php8.1-ldap \
       php8.1-msgpack php8.1-igbinary php8.1-redis php8.1-swoole \
       php8.1-memcached php8.1-pcov php8.1-xdebug \
       php8.1-amqp php8.1-imagick \
    && sed -i 's/<policy domain="coder" rights="none" pattern="PDF" \/>/<policy domain="coder" rights="read|write" pattern="PDF" \/>/g' /etc/ImageMagick-6/policy.xml \
    && php -r "readfile('https://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
    && curl -sL https://deb.nodesource.com/setup_$NODE_VERSION.x | bash - \
    && apt-get install -y nodejs \
    && npm install -g npm \
    && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
    && echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \
    && sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' \
    && curl -sS https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
    && apt-get update \
    && apt-get install -y yarn \
    && apt-get install -y mysql-client \
    && apt-get install -y postgresql-client-14 \
    && apt-get -y autoremove \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN setcap "cap_net_bind_service=+ep" /usr/bin/php8.1

RUN groupadd --force -g $WWWGROUP dstr
RUN useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u 1337 dstr

COPY start-container /usr/local/bin/start-container
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY php.ini /etc/php/8.1/cli/conf.d/99-dstr.ini
RUN chmod +x /usr/local/bin/start-container

EXPOSE 8000

ENTRYPOINT ["start-container"]

Then I run command: docker build -t np1tshkodenko/api:8.1 .

I got the following output:

shkodenko.t@WSH63676:~/2023-02-07_lara/zoning-backend/docker/api/8.1$ docker build -t np1tshkodenko/api:8.1 .
[+] Building 149.0s (13/18)                                                                                                                                                              
 => [internal] load build definition from Dockerfile                                                                                                                                0.0s
 => => transferring dockerfile: 2.62kB                                                                                                                                              0.0s 
 => [internal] load .dockerignore                                                                                                                                                   0.0s 
 => => transferring context: 2B                                                                                                                                                     0.0s 
 => [internal] load metadata for docker.io/library/ubuntu:20.04                                                                                                                     2.8s 
 => [auth] library/ubuntu:pull token for registry-1.docker.io                                                                                                                       0.0s
 => [internal] load build context                                                                                                                                                   0.0s 
 => => transferring context: 1.05kB                                                                                                                                                 0.0s 
 => [ 1/13] FROM docker.io/library/ubuntu:20.04@sha256:4a45212e9518f35983a976eead0de5eecc555a2f047134e9dd2cfc589076a00d                                                             2.1s 
 => => resolve docker.io/library/ubuntu:20.04@sha256:4a45212e9518f35983a976eead0de5eecc555a2f047134e9dd2cfc589076a00d                                                               0.0s
 => => sha256:4a45212e9518f35983a976eead0de5eecc555a2f047134e9dd2cfc589076a00d 1.13kB / 1.13kB                                                                                      0.0s 
 => => sha256:bffb6799d706144f263f4b91e1226745ffb5643ea0ea89c2f709208e8d70c999 424B / 424B                                                                                          0.0s 
 => => sha256:e40cf56b4be35b04f620bc9cfbef80038fd7370d4ed36d90676223174ecbf0b0 2.30kB / 2.30kB                                                                                      0.0s 
 => => sha256:b549f31133a955f68f9fa0d93f18436c4a180e12184b999a8ecf14f7eaa83309 27.50MB / 27.50MB                                                                                    1.1s 
 => => extracting sha256:b549f31133a955f68f9fa0d93f18436c4a180e12184b999a8ecf14f7eaa83309                                                                                           0.9s
 => [ 2/13] WORKDIR /var/www/html                                                                                                                                                   0.1s
 => [ 3/13] RUN ln -snf /usr/share/zoneinfo/UTC /etc/localtime && echo UTC > /etc/timezone                                                                                          0.2s
 => [ 4/13] RUN apt-get update      && apt-get install -y apt-transport-https                                                                                                       6.6s
 => [ 5/13] RUN apt-get install -y software-properties-common gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2     && mkdir -p ~/.  58.5s
 => [ 6/13] RUN LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php     && apt-get update     && apt-get install -y php8.1-cli php8.1-dev        php8.1-pgsql php8.1-sqlite3 php8  78.1s 
 => [ 7/13] RUN setcap "cap_net_bind_service=+ep" /usr/bin/php8.1                                                                                                                   0.2s 
 => ERROR [ 8/13] RUN groupadd --force -g $WWWGROUP dstr                                                                                                                            0.2s 
------                                                                                                                                                                                   
 > [ 8/13] RUN groupadd --force -g $WWWGROUP dstr:                                                                                                                                       
#12 0.211 groupadd: invalid group ID 'dstr'                                                                                                                                              
------                                                                                                                                                                                   
executor failed running [/bin/sh -c groupadd --force -g $WWWGROUP dstr]: exit code: 3
shkodenko.t@WSH63676:~/2023-02-07_lara/zoning-backend/docker/api/8.1$

How can I fix this error to complete a build?

I've tried to execute docker build -t np1tshkodenko/api:8.1 . and I'm expecting to get a working container build.


Solution

  • You need to pass a value for the WWWGROUP variable when you build the image.

    I don't know what a sensible value would be, but let's say that you want the value to be 'mygroup'. Then you'd do

    docker build -t np1tshkodenko/api:8.1 --build-arg WWWGROUP=mygroup .