publishes the port 12345 from the container to the host:
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0adac614c107 alpine:latest "sh -c 'apk add --no…" 29 seconds ago Up 29 seconds 0.0.0.0:12345->12345/tcp, :::12345->12345/tcp src-netcat-server-run-79dad3a4579c
while the same using podman-compose run:
podman-compose run -p 12345:12345 netcat-server
does not publish the port:
$ podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
acc4cd67b10a docker.io/library/alpine:latest sh -c apk add --n... 7 seconds ago Up 8 seconds src_netcat-server_tmp59130
$ podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
60e58363e0c0 docker.io/library/alpine:latest sh -c apk add --n... 1 second ago Up 1 second 0.0.0.0:12345->12345/tcp src_netcat-server_tmp20781
The new block if args.publish: is stategically put after the block if not args.service_ports:, which is emptying cnt['ports'] when --service-ports is not passed.
Otherwise the ports added by --publish would be immediately emptied when --service-ports is not passed, which is not what is expected :D.
Documentation
docker-compose run options: https://docs.docker.com/reference/cli/docker/compose/run/#options
Explanations
Using the below
docker-compose.yml
:The below
docker-compose run
command:publishes the port 12345 from the container to the host:
while the same using
podman-compose run
:does not publish the port:
The changes in this pull request aims to add the implementation of the
--publish
options inpodman-compose run
, which was completely forgotten.--publish
was added to the parser arguments: https://github.com/containers/podman-compose/blob/2681566580b4eaadfc5e6000ad19e49e56006e2b/podman_compose.py#L3002-L3007 but then never used later (no occurences ofargs.publish
).These changes allow the expected behavior:
The new block
if args.publish:
is stategically put after the blockif not args.service_ports:
, which is emptyingcnt['ports']
when--service-ports
is not passed. Otherwise the ports added by--publish
would be immediately emptied when--service-ports
is not passed, which is not what is expected :D.