I'm working on creating an alpine postfix container, using https://www.iops.tech/blog/postfix-in-alpine-docker-container/. I figure as it's under a year old, it should be good. I set it up, with the only difference being it's done in docker-compose instead of the container directly. I did test it as written in the blog (running docker directly), and it seems to work. But when I do a dc up -d postfix
using these configs:
postfix:
build:
context: ./docker/postfix
container_name: postfix
ports:
- 8025:25
environment:
- POSTFIX_SMTP_HELO_NAME=localhost
- POSTFIX_MYORIGIN=localhost
- POSTFIX_MYHOSTNAME=localhost
I get for postfix Cannot create container for service postfix: invalid port specification: "481525"
.
CodePudding user response:
Change your ports specification to wrap the ports in quotes
ports:
- "8025:25"
When mapping ports in the
HOST:CONTAINER
format, you may experience erroneous results when using a container port lower than 60, because YAML parses numbers in the formatxx:yy
as a base-60 value. For this reason, we recommend always explicitly specifying your port mappings as strings.
https://docs.docker.com/compose/compose-file/compose-file-v3/#short-syntax-1
I recommend always wrapping literal values in quotes, to be explicit and to be consistent, to try and avoid these gotchas.
Full conversion
This is the command from the article
docker run \
-d \
--rm \
--init \
--env POSTFIX_SMTP_HELO_NAME=localhost \
--env=POSTFIX_MYORIGIN=localhost \
--env=POSTFIX_MYHOSTNAME=localhost \
--name postfix-alpine \
-p 8025:25 \
postfix-alpine:latest
I would translate it to a docker-compose.yml
like this:
(I haven't tested this)
version: "3.9"
services:
postfix:
image: postfix-alpine:latest
container_name: postfix-alpine
build:
context: "./docker/postfix"
ports:
- "8025:25"
environment:
POSTFIX_SMTP_HELO_NAME: "localhost"
POSTFIX_MYORIGIN: "localhost"
POSTFIX_MYHOSTNAME: "localhost"