With only build: ., Compose names the image after the project and service, something like myproject-app. Add an image: line next to it and that becomes the tag of the result.
services:
app:
build: .
image: registry.example.com/app:1.4.0
docker compose build app
docker compose push app
Now the build produces registry.example.com/app:1.4.0, and docker compose push knows where to send it. On another machine the same file can pull that tag instead of building, as long as the image exists in the registry.
I like this for small self-built tools. Bumping the version in the image: line means the old build stays on disk under its own tag, so going back is a matter of changing the line again.
Compose decides whether to build or pull based on pull_policy. By default it pulls when the image is missing and builds only when the pull fails, which can quietly start an old image from the registry instead of your local changes. During development, run docker compose up -d --build to be sure the image is rebuilt, or set pull_policy: build on that service.
Further reading: Compose Build Specification