You change an environment variable in compose.yaml, run docker compose restart, and nothing changes. That is expected behaviour, and it confuses a lot of people.
restart stops and starts the existing containers. The containers keep the configuration they were created with, so a new variable, port, volume or image tag never reaches them. The docs say it plainly: changes to the Compose file are not reflected after a restart.
What you want instead is:
docker compose up -d
Compose compares the file with the running containers and recreates only the services whose configuration changed. The others keep running untouched. For one service:
docker compose up -d web
restart still has its place in my view, but only for what it is good at: an app that needs a kick after it reread a config file from a mounted volume, or one that got stuck.
Recreating a container throws away anything it wrote outside its volumes. If an app keeps state in its own filesystem, that state is gone after up -d recreates it, and a restart would have kept it. Check your volumes before you rely on recreating, and use docker diff if you are unsure what the container writes.
Further reading: docker compose restart, docker compose up