Container discovery in docker swarm

I am new to docker. I have different stacks in docker swarm. Now, I want to resolve container name outside of stack. If I use a machine IP with exposed port then it is working fine but I want that it is resolvable by container name. How can achieve this?