How to run a docker command remotely via SSH?

  docker, ssh

I’m trying to remotely run a docker command via SSH using the following command.

ssh [email protected] "docker system prune -af"

The error I receive is:

unknown shorthand flag: 'X' in -X. See 'docker system prune --help'.

Note that I use passwordless authentication with SSH. The command above also does not require any user interaction. I have already tried running other simple bash commands like ls and they work with no issues.

I have already tried to use the -tt command as suggested by this SO post to no avail.

What is causing this issue and how can I run my prune command without having to first SSH into my remote machine and then running the command directly in the machine?

Source: Docker Questions