It is convenient to recreate the container when updating, and the world and settings should survive this action. In character itzg/minecraft-server game data is in /data. In the example below, this directory is associated with the folder data next to compose.yaml.
The example is designed for already installed Docker with Compose and a separate Minecraft Java 1.21.1 server. The version is clearly selected: if you set up another issue, replace it with a suitable generation of Java. The image tag latest and meaning LATEST for the game can change the environment without a separate decision of the owner.