Another one bites the mail! (php container with sendmail)

Hi there!
It does a long time I’m trying to use mail() function in a php container. I have postfix and sendmail installed on the host (ubuntu server) and it works like a charm on my website (under apache installed on the host).
I’m discovering Docker and wanted to try it with my website first.
Here is my docker-compose.yml

services:
  mysql:
    build:
      context: .
      dockerfile: Dockerfile_mysql
    image: mysql:latest
    environment:
      MYSQL_ROOT_PASSWORD: secret
      MYSQL_DATABASE: sql_user
      MYSQL_USER: sql_user
      MYSQL_PASSWORD: sql_pswd
    volumes:
      - ./mysql_data:/var/lib/mysql
    networks:
      - www_sql
  phpmyadmin:
    image: phpmyadmin/phpmyadmin:latest
    links:
      - mysql
    depends_on:
      - mysql
    environment:
      PMA_HOST: mysql
      MYSQL_USER: sql_user
      MYSQL_PASSWORD: sql_pswd
    ports:
      - 8083:80
    networks:
      - web_test
      - www_sql
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=web_test"
      - "traefik.http.routers.phpmyadmin.rule=(Host(`myadmin.myserver.com`))"
  php:
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - ./src:/var/www/html
    ports:
      - 1025:25
      - 8084:80
    links:
      - mysql
    depends_on:
      - mysql
      - phpmyadmin
    networks:
      - web_test
      - www_sql
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=web_test"
      - "traefik.http.routers.php.rule=(Host(`mysite.myserver.com`))"
      - "traefik.http.services.php.loadBalancer.server.port=80"

volumes:
  mysql_data:
  src:

networks:
  web_test:
    external: true
  www_sql:
    external: true

and my Dockerfile:

FROM php:8.2-apache
RUN a2enmod rewrite
RUN echo 'ServerName 127.0.0.1' >> /etc/apache2/apache2.conf
RUN docker-php-ext-install mysqli
RUN apt-get update && \
        apt-get install -y \
                sendmail zlib1g-dev libzip-dev
RUN echo "sendmail_path=/usr/sbin/sendmail -t -i" >> /usr/local/etc/php/conf.d/sendmail.ini
RUN rm -rf /var/lib/apt/lists/*

RUN docker-php-ext-install pdo_mysql
RUN docker-php-ext-install zip

RUN sed -i '/#!\/bin\/sh/aservice sendmail restart' /usr/local/bin/docker-php-entrypoint
RUN sed -i '/#!\/bin\/sh/aecho "$(hostname -i)\t$(hostname) $(hostname).localhost" >> /etc/hosts' /usr/local/bin/docker-php-entrypoint

#RUN apt-get update && apt-get install -y iputils-ping

COPY src/ /var/www/html/

I can reach my website and send emails without errors in php script. But the emails stay stuck in queue:

root@f40599b785df:/var/www/html# mailq
MSP Queue status...
                /var/spool/mqueue-client (1 request)
-----Q-ID----- --Size-- -----Q-Time----- ------------Sender/Recipient-----------
52Q8LT6F000402      503 Wed Mar 26 08:21 www-data
                 (Deferred: 421 4.3.0 collect: Cannot write ./df52Q8LTMo000403)
                                         myemail@myserver.com
                Total requests: 1
MTA Queue status...
/var/spool/mqueue is empty
                Total requests: 0

I can’t receive them, but I can’t figure why… I’m not able to tell if it’s a problem with ports, or permissions… I’m not able to tell if container is trying to use the sendmail configuration on my host or not… Like I said I’m discovering Docker and emails are a secret for me!

If someone could help me…
Thank you!

You want to send emails to the world or just to your host user inbox?

Hi!
I want to send emails to the world, yes!

Since it says

It seems to be a permission issue, but nothin in a container can see configuration on the host unless you mount specifi folders or files into that container.