If it’s enough to simply sort by output column, you can use the following:
docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}" | (read -r; printf "%s\n" "$REPLY"; sort -k 3 )
I also added a code for skipping the table headers and sorting only ps output data.