containers / podman-compose

a script to run docker-compose.yml using podman
GNU General Public License v2.0
4.86k stars 465 forks source link

--podman-args args are not passed to podman #707

Open gwallet opened 1 year ago

gwallet commented 1 year ago

Describe the bug I want to use the remote capability of docker to deploy containers on a remote host. podman-compose knows nothing about this feature, but the doc says:

...
--podman-args args    custom global arguments to be passed to `podman`
...

I'm understanding that one can pass argument to podman thanks to --podman-args. The hope here is to let podman-compose talk locally to podman, using --podman-args="--remote" the later will be driving a remote host, and that it will be smooth.

There are also several --podman-{CMD}-args flags to pass arguments to dedicated command, which is not what I'm looking for. (at least, not at the moment)

To Reproduce Steps to reproduce the behavior:

  1. setup a remote host with podman installed and ready to serve remotely

    • Fedora Server 38 in a small VM in VirtualBox
    • setup remote access with key pairs (ssh-copy-id …)
    • enable podman.socket on the host
    • make a container running
  2. add a podman connection to the host

    • $ podman system connection add --default remote ssh://user@remote
  3. check the remote access with podman

    • $ podman --remote container ls
    • ✅ it returns the list of running container on the remote host and not on the localhost
  4. check the remote access with podman-compose

    • $ podman-compose --project-name my-project --podman-args="--remote" ps
    • ❎ the following error occurs
      podman-compose version: 1.0.6
      ['podman', '--version', '']
      using podman version: 4.5.0
      podman ps --remote -a --filter label=io.podman.compose.project=my-project
      Error: unknown flag: --remote
      See 'podman ps --help'
      exit code: 125

      The --remote flag is set after ps and not after podman

  5. podman is doing well when asking with the right command line:

    • $ podman --remote ps -a --filter label=io.podman.compose.project=my-project list all the container running remotely

Expected behavior Running podman-compose --help says

...
--podman-args args    custom global arguments to be passed to `podman`
...

I'm expecting the args to be passed to podman and not the the sub-command: Expecting: ✅ podman --remote ps -a --filter label=io.podman.compose.project=my-project Got: ❎ podman ps --remote -a --filter label=io.podman.compose.project=my-project

Actual behavior Actually, arguments sent to podman-compose via --podman-args are given to the sub-command and not to podman globally as mentioned in the doc.

Output

$ podman-compose version
podman-compose version: 1.0.6
['podman', '--version', '']
using podman version: 4.5.0
podman-compose version 1.0.6
podman --version 
podman version 4.5.0
exit code: 0

Environment:

Additional context

As a workaround, it's always possibe to send podman-compose commands via SSH, but want to avoid sending the compose file via SCP, and keeping things on the driver computer.

I hope it's clear, if not I'll be happy to clarify 🙂

Regards,

onursoyer commented 1 year ago

I can confirm the error mentioned above.

When executing the following code, it throws an error:

podman-compose --podman-args "-c p1-root" up
podman-compose version: 1.0.6
['podman', '--version', '']
using podman version: 4.5.0
** excluding:  set()
['podman', 'ps', '-c', 'p1-root', '--filter', 'label=io.podman.compose.project=docker', '-a', '--format', '{{ index .Labels "io.podman.compose.config-hash"}}']
Error: unknown shorthand flag: 'c' in -c
See 'podman ps --help'
Traceback (most recent call last):
  File "/usr/bin/podman-compose", line 33, in <module>
    sys.exit(load_entry_point('podman-compose==1.0.6', 'console_scripts', 'podman-compose')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/podman_compose.py", line 2940, in main
    podman_compose.run()
  File "/usr/lib/python3.11/site-packages/podman_compose.py", line 1422, in run
    cmd(self, args)
  File "/usr/lib/python3.11/site-packages/podman_compose.py", line 1753, in wrapped
    return func(*args, **kw)
           ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/podman_compose.py", line 2037, in compose_up
    compose.podman.output(
  File "/usr/lib/python3.11/site-packages/podman_compose.py", line 1097, in output
    return subprocess.check_output(cmd_ls)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/subprocess.py", line 466, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['podman', 'ps', '-c', 'p1-root', '--filter', 'label=io.podman.compose.project=docker', '-a', '--format', '{{ index .Labels "io.podman.compose.config-hash"}}']' returned non-zero exit status 125.

It looks like podman-compose executes podman ps first and then inserts the 'podman-args' arguments afterwards. Therefore, it does not work. The execution order should be reversed as for example podman -c p1 ps instead of podman ps -c p1.

francoism90 commented 11 months ago

Did you ever found a solution?

This seems to work for me:

podman-compose --podman-run-args="--cpus=1.5" up -d 
Bahlaouane-Hamza commented 8 months ago

Install podman-remote, setup a remote connection and then use it like so

$ podman-compose --podman-path="/usr/bin/podman-remote" ps
Jakuje commented 1 month ago

Note, that there are still conrner cases that dont work with the approach if the compose references some local volumes, their absolute path needs to exist on the remote machine running the podman.

francoism90 commented 1 month ago

I've moved on to Quadlet e.g systemd containers. This also gives you the benefits of applying quota flags, and you can even apply system(d) settings.

The only disadvantages is that it only works for systemd and the user needs to place/sync container files, instead of providing one simple compose file.

hunter86bg commented 1 month ago

I was attempting the following but it also fails:

podman-compose --podman-start-args="--health-on-failure=restart" up -d

Sadly, podman-compose doesn't support restart pod on failure.