Why I can not execute command?

Next does not work:

nomad alloc exec -task postgres-task 48a14dcd-63e2-e2d0-d31e-2a3ecd4b9240 psql -h 127.0.0.1 -U postgres
Usage: nomad alloc exec [options] <allocation> <command>

  Run command inside the environment of the given allocation and task.

  When ACLs are enabled, this command requires a token with the 'alloc-exec',
  'read-job', and 'list-jobs' capabilities for the allocation's namespace. If
  the task driver does not have file system isolation (as with 'raw_exec'),
  this command requires the 'alloc-node-exec', 'read-job', and 'list-jobs'
  capabilities for the allocation's namespace.
...

Though this works:

nomad alloc exec -task postgres-task 48a14dcd-63e2-e2d0-d31e-2a3ecd4b9240 psql -U postgres
psql (11.11 (Debian 11.11-1.pgdg90+1), server 11.12 (Debian 11.12-1.pgdg90+1))
Type "help" for help.

postgres=#

Hi @EugenKon,

Nomad exec is treating the -h as the --help argument. You can run the command inside a shell as shown below.

nomad alloc exec -task postgres-task 48a14dcd-63e2-e2d0-d31e-2a3ecd4b9240 /bin/sh -c 'psql -h 127.0.0.1 -U postgres'

I hope this helps.

@Ranjandas Thank you.

Seems like a bug. It should not interpret it, because it does not match nomad alloc exec [options] <allocation> <command> [<args>...].

Looks like if nomad implement -c flag, then bash -c will stop to work )