Python Subprocess returns nothing without error

  docker, python, python-3.x, subprocess

I’ve been trying to write a function which get the passed parameter via runtime.
Once I run the script from CLI, it returns nothing without any errors

[email protected]:/scripts# python3 2019

Here is a script

def get_service_name_from_port(port):
    service_container_name = subprocess.check_output("docker service ls --format "{{.Ports}},{{.Name}},{{.ID}},{{.Image}}" | grep {port} | cut -d ',' -f2".format(port=port), shell=True, stdout=subprocess.PIPE)
    return service_container_name.decode()

if __name__ == "__main__":
    import sys
    port = sys.argv[0]
    print( get_service_name_from_port(port))

I’ve tried the same command docker service (inside subprocess.check_output) and the results are produced perfectly.

$ docker service ls --format "{{.Ports}},{{.Name}},{{.ID}},{{.Image}}" | grep "2019" | cut -d ',' -f2

and the result


Please suggest how to manage to get the output correctly

Source: Docker Questions