Initialize swarm mode:
root@ip-172-31-44-207:/home/ubuntu# docker swarm init --advertise-addr 172.31.44.207 Swarm initialized: current node (4mj61o
You can execute commands by filtering container name without needing to pass the entire swarm container hash, just by the service name. Like this:
docker exec $(docker ps -q -f name=servicename) ls