### Production Deployment with docker-compose.yml Source: https://context7.com/juanluisbaptiste/docker-postfix/llms.txt Deploy Postfix in production using a `docker-compose.yml` file. This setup reads configuration from a `.env` file, ensures the container always restarts, and mounts the host's `/etc/localtime` for accurate log timestamps. Start in production mode with `docker compose up -d` and view logs with `docker logs -f postfix`. ```yaml # docker-compose.yml name: postfix services: postfix: image: juanluisbaptiste/postfix:latest expose: - "25" env_file: - .env restart: always volumes: - "/etc/localtime:/etc/localtime:ro" ``` ```bash # Copy and configure the env file cp .env.example .env # Edit .env with your SMTP credentials: # SMTP_SERVER=smtp.bar.com # SMTP_USERNAME=foo@bar.com # SMTP_PASSWORD=supersecretpassword # SERVER_HOSTNAME=helpdesk.mycompany.com # Start in production mode docker compose up -d # View real-time mail logs docker logs -f postfix ``` -------------------------------- ### Configure SMTP Password from File Source: https://github.com/juanluisbaptiste/docker-postfix/blob/master/README.md Example of mounting a password file into the container to avoid exposing sensitive credentials in environment variables. ```bash -e SMTP_PASSWORD_FILE=/secrets/smtp_password -v $(pwd)/secrets/:/secrets/ ``` -------------------------------- ### Configure SMTP Username from File Source: https://github.com/juanluisbaptiste/docker-postfix/blob/master/README.md Example of mounting a username file into the container to avoid exposing sensitive credentials in environment variables. ```bash -e SMTP_USERNAME_FILE=/secrets/smtp_username -v $(pwd)/secrets/:/secrets/ ``` -------------------------------- ### Docker Compose for Production Source: https://github.com/juanluisbaptiste/docker-postfix/blob/master/README.md Command to start the Postfix container in detached mode using Docker Compose, recommended for production environments. ```bash sudo docker-compose up -d ``` -------------------------------- ### Run Basic SMTP Relay Container Source: https://context7.com/juanluisbaptiste/docker-postfix/llms.txt Starts a Postfix relay container exposing port 25 and connecting to an upstream SMTP server with TLS and SASL authentication. Verify the container and Postfix startup using `docker logs`. ```bash docker run -d --name postfix -p "25:25" \ -e SMTP_SERVER=smtp.bar.com \ -e SMTP_PORT=587 \ -e SMTP_USERNAME=foo@bar.com \ -e SMTP_PASSWORD=supersecretpassword \ -e SERVER_HOSTNAME=helpdesk.mycompany.com \ juanluisbaptiste/postfix:latest # Verify container is running and Postfix started successfully docker logs postfix # Expected output includes lines like: # Setting configuration option myhostname with value: helpdesk.mycompany.com # Setting configuration option relayhost with value: [smtp.bar.com]:587 # Adding SASL authentication configuration # postfix/master[1]: daemon started -- version 3.x.x, configuration /etc/postfix ``` -------------------------------- ### Configure SMTP Networks Source: https://github.com/juanluisbaptiste/docker-postfix/blob/master/README.md Example of setting the SMTP_NETWORKS environment variable to allow specific subnets to use the relay. Note: This requires host network mode. ```bash -e `SMTP_NETWORKS='xxx.xxx.xxx.xxx/xx,xxx.xxx.xxx.xxx/xx'` ``` -------------------------------- ### Build Docker Image from Source Source: https://context7.com/juanluisbaptiste/docker-postfix/llms.txt Build the Postfix Docker image locally using the provided `Dockerfile` and an override Compose file for local development. Clone the repository, navigate to the directory, and use `docker build` or `docker compose` commands. ```bash # Clone and build manually git clone https://github.com/juanluisbaptiste/docker-postfix.git cd docker-postfix # Direct Docker build docker build -t juanluisbaptiste/postfix:local . # Or use the override compose file (builds with :dev tag) docker compose -f docker-compose.yml -f docker-compose.override.yml build ``` -------------------------------- ### Build Docker Postfix Image Source: https://github.com/juanluisbaptiste/docker-postfix/blob/master/README.md Build the Docker image locally from the cloned repository. Ensure you are in the 'docker-Postfix' directory. ```bash cd docker-Postfix sudo docker build -t juanluisbaptiste/postfix . ``` -------------------------------- ### Run Docker Postfix Container (Publish All Ports) Source: https://github.com/juanluisbaptiste/docker-postfix/blob/master/README.md Command to run the Postfix container and publish all exposed ports, useful for inter-container communication. ```bash docker run -d --name postfix -P \ -e SMTP_SERVER=smtp.bar.com \ -e SMTP_USERNAME=foo@bar.com \ -e SMTP_PASSWORD=XXXXXXXX \ -e SERVER_HOSTNAME=helpdesk.mycompany.com \ juanluisbaptiste/postfix ``` -------------------------------- ### View Postfix Logs in Real Time Source: https://github.com/juanluisbaptiste/docker-postfix/blob/master/README.md Command to follow the logs of the running Postfix container in real time, useful for monitoring and debugging. ```bash docker logs -f postfix ``` -------------------------------- ### Build Docker Postfix Image with Docker Compose Source: https://github.com/juanluisbaptiste/docker-postfix/blob/master/README.md Build the Docker image using Docker Compose. This is an alternative to the direct docker build command. ```bash sudo docker-compose build ``` -------------------------------- ### Configure SMTP Server and Hostname Source: https://context7.com/juanluisbaptiste/docker-postfix/llms.txt Demonstrates the required `SMTP_SERVER` and `SERVER_HOSTNAME` environment variables. The container will exit with an error if these are not set. `mydomain` is derived from `SERVER_HOSTNAME` unless `DOMAIN` is specified. ```bash # Container will fail fast with a clear error if required vars are missing docker run --rm \ -e SMTP_SERVER=smtp.sendgrid.net \ juanluisbaptiste/postfix:latest # Output: SERVER_HOSTNAME is not set (exits with code 1) # Correct usage docker run -d --name postfix -p "25:25" \ -e SMTP_SERVER=smtp.sendgrid.net \ -e SMTP_PORT=587 \ -e SMTP_USERNAME=apikey \ -e SMTP_PASSWORD=SG.xxxxxxxxxxxx \ -e SERVER_HOSTNAME=app.mycompany.com \ juanluisbaptiste/postfix:latest # Postfix mydomain will be automatically set to "mycompany.com" ``` -------------------------------- ### Use Secret Files for Credentials Source: https://context7.com/juanluisbaptiste/docker-postfix/llms.txt Recommends using `SMTP_USERNAME_FILE` and `SMTP_PASSWORD_FILE` for production and Kubernetes deployments to avoid plain-text environment variables. Ensure file permissions are set to `600`. ```bash # Create secret files on the host mkdir -p ./secrets echo "foo@bar.com" > ./secrets/smtp_username echo "supersecretpass" > ./secrets/smtp_password chmod 600 ./secrets/* # Run with file-based credentials docker run -d --name postfix -p "25:25" \ -e SMTP_SERVER=smtp.bar.com \ -e SERVER_HOSTNAME=helpdesk.mycompany.com \ -e SMTP_USERNAME_FILE=/secrets/smtp_username \ -e SMTP_PASSWORD_FILE=/secrets/smtp_password \ -v "$(pwd)/secrets:/secrets:ro" \ juanluisbaptiste/postfix:latest # In Kubernetes, use a Secret volume mount and reference the mount path: # env: # - name: SMTP_SERVER # value: "smtp.bar.com" # - name: SMTP_PASSWORD_FILE # value: "/secrets/smtp_password" # volumeMounts: # - name: smtp-secret # mountPath: /secrets # readOnly: true ``` -------------------------------- ### Send Test Email from Host Source: https://context7.com/juanluisbaptiste/docker-postfix/llms.txt Send a test email from the host machine to the running Postfix relay. Ensure port 25 is exposed from the container to the host. ```bash echo "Test body" | mailx -s "Test Subject" \ -S smtp=smtp://localhost:25 \ -S from=sender@mycompany.com \ recipient@example.com ``` -------------------------------- ### Pull Docker Postfix Image from Docker Hub Source: https://github.com/juanluisbaptiste/docker-postfix/blob/master/README.md Pull the latest prebuilt Docker image for Postfix from Docker Hub. This is the recommended way to use the image if you don't need to build it yourself. ```bash sudo docker pull juanluisbaptiste/postfix:latest ``` -------------------------------- ### Configure Logging, Message Size, Encoding, and Timezone Source: https://context7.com/juanluisbaptiste/docker-postfix/llms.txt Configure miscellaneous settings like logging subjects, message size limits, SMTPUTF8 encoding, header addition, and timezone using environment variables. Monitor logs including subject lines with `docker logs -f postfix`. ```bash docker run -d --name postfix -p "25:25" \ -e SMTP_SERVER=smtp.bar.com \ -e SMTP_USERNAME=foo@bar.com \ -e SMTP_PASSWORD=mypassword \ -e SERVER_HOSTNAME=app.mycompany.com \ -e LOG_SUBJECT=yes \ -e MESSAGE_SIZE_LIMIT=20480000 \ -e SMTPUTF8_ENABLE=no \ -e ALWAYS_ADD_MISSING_HEADERS=yes \ -e TZ=America/New_York \ juanluisbaptiste/postfix:latest # Monitor logs including subject lines: docker logs -f postfix ``` -------------------------------- ### Run Docker Postfix Container Source: https://github.com/juanluisbaptiste/docker-postfix/blob/master/README.md Basic command to run the Postfix container, exposing port 25 and setting essential environment variables for SMTP relay. ```bash docker run -d --name postfix -p "25:25" \ -e SMTP_SERVER=smtp.bar.com \ -e SMTP_USERNAME=foo@bar.com \ -e SMTP_PASSWORD=XXXXXXXX \ -e SERVER_HOSTNAME=helpdesk.mycompany.com \ juanluisbaptiste/postfix ``` -------------------------------- ### Enable Debugging Output Source: https://github.com/juanluisbaptiste/docker-postfix/blob/master/README.md Set the DEBUG environment variable to 'yes' to enable verbose output for troubleshooting the container. ```bash _DEBUG=yes ``` -------------------------------- ### Enable Debug Output for Postfix Relay Source: https://context7.com/juanluisbaptiste/docker-postfix/llms.txt Run the Postfix container with debug enabled to see detailed logs of the run.sh script execution. This is useful for troubleshooting configuration issues. ```bash docker run -d --name postfix-debug -p "25:25" \ -e SMTP_SERVER=smtp.bar.com \ -e SMTP_USERNAME=foo@bar.com \ -e SMTP_PASSWORD=mypassword \ -e SERVER_HOSTNAME=helpdesk.mycompany.com \ -e DEBUG=yes \ juanluisbaptiste/postfix:local docker logs -f postfix-debug ``` -------------------------------- ### Send Test Email from Another Docker Container Source: https://context7.com/juanluisbaptiste/docker-postfix/llms.txt Send a test email from a temporary Alpine container connected to the same Docker network as the Postfix relay. This verifies inter-container communication. ```bash docker run --rm --network container:postfix alpine sh -c \ "apk add --no-cache mailx && \ echo 'Test body' | mailx -s 'Hello' \ -S smtp=smtp://postfix:25 \ -S from=app@mycompany.com \ recipient@example.com" ``` -------------------------------- ### Configure Port 465 for SMTPS (Implicit TLS) Source: https://context7.com/juanluisbaptiste/docker-postfix/llms.txt When `SMTP_PORT` is set to `465`, the container automatically configures Postfix for implicit TLS (SMTPS) by enabling `smtp_tls_wrappermode = yes` and `smtp_tls_security_level = encrypt`. The default port is `587` for STARTTLS. ```bash # Relay via SMTPS (implicit TLS on port 465) docker run -d --name postfix -p "25:25" \ -e SMTP_SERVER=smtp.example.com \ -e SMTP_PORT=465 \ -e SMTP_USERNAME=user@example.com \ -e SMTP_PASSWORD=mypassword \ -e SERVER_HOSTNAME=relay.mycompany.com \ juanluisbaptiste/postfix:latest # Logs will confirm: # Setting configuration option smtp_tls_wrappermode with value: yes # Setting configuration option smtp_tls_security_level with value: encrypt ``` -------------------------------- ### Rewrite From Header with OVERWRITE_FROM Source: https://context7.com/juanluisbaptiste/docker-postfix/llms.txt Use the `OVERWRITE_FROM` environment variable to rewrite the `From:` header and `sender_canonical_maps` for all relayed messages. This is useful when an upstream SMTP provider requires the authenticated account address. ```bash # Rewrite all outgoing From: headers to a single address docker run -d --name postfix -p "25:25" \ -e SMTP_SERVER=smtp.gmail.com \ -e SMTP_PORT=587 \ -e SMTP_USERNAME=noreply@mycompany.com \ -e SMTP_PASSWORD=apppassword \ -e SERVER_HOSTNAME=app.mycompany.com \ -e 'OVERWRITE_FROM=No Reply ' \ juanluisbaptiste/postfix:latest # All emails relayed will have their From header replaced: # Before: From: user@internal.lan # After: From: No Reply ``` -------------------------------- ### Expand Allowed Networks with SMTP_NETWORKS Source: https://context7.com/juanluisbaptiste/docker-postfix/llms.txt Append additional IPv4 or IPv6 CIDR ranges to the default `mynetworks` using the `SMTP_NETWORKS` environment variable. This requires the container to run with Docker host networking (`--network host`). ```bash # Add extra IPv4 and IPv6 subnets (requires host network mode) docker run -d --name postfix --network host \ -e SMTP_SERVER=smtp.bar.com \ -e SMTP_USERNAME=foo@bar.com \ -e SMTP_PASSWORD=mypassword \ -e SERVER_HOSTNAME=relay.mycompany.com \ -e SMTP_NETWORKS='203.0.113.0/24,2001:db8::/32' \ juanluisbaptiste/postfix:latest # Resulting Postfix mynetworks will be: # 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 203.0.113.0/24, [2001:db8::]/32 ``` -------------------------------- ### Add Relay Tracking Header with SMTP_HEADER_TAG Source: https://context7.com/juanluisbaptiste/docker-postfix/llms.txt Prepend a custom `RelayTag:` header to outgoing emails using the `SMTP_HEADER_TAG` environment variable. This helps identify which relay instance handled a message for troubleshooting. ```bash docker run -d --name postfix -p "25:25" \ -e SMTP_SERVER=smtp.bar.com \ -e SMTP_USERNAME=foo@bar.com \ -e SMTP_PASSWORD=mypassword \ -e SERVER_HOSTNAME=helpdesk.mycompany.com \ -e SMTP_HEADER_TAG=PROD-RELAY-01 \ juanluisbaptiste/postfix:latest # Outgoing emails will contain additional headers: # RelayTag: PROD-RELAY-01 # MIME-Version: 1.0 # ... ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.