Use docker build to build the image. The thing with docker swarm is that it doesn't work with tags instead it uses the image id while executing a stack deploy.
docker build -t imagename --no-cache .
You can use this image on your Docker Compose file like the following:
version: '3'
services:
example-service:
image: imagename:latest