Use a multi-stage build, something like this
FROM php:8.2-cli as builder
RUN apt-get update && apt-get install -y nodejs npm
RUN npm install -g eslint
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
php composer-setup.php && \
php -r "unlink('composer-setup.php');"
RUN ./composer.phar global require drupal/coder
FROM php:8.2-cli
COPY --from=builder /root/.composer /root/.composer
COPY --from=builder /usr/local/bin/eslint /usr/local/bin/eslint
ENV PATH="/root/.composer/vendor/bin:${PATH}"
WORKDIR /code
Use a multi-stage build, something like this