How to create persistent volume for postgresql container

Hi everyone, I am new to docker and I have seen that the files are deleted when the system is restarted.

I would like to understand how to create a persistent volume.

At the moment I have only created the main postgres user.

From the guides I noticed that the yml file docker-compose.yml must be launched

How can I create this file?

From the guides I saw that the strings to be saved are the following:

docker-compose.yml

version: '3.1'
services:
   db:
     image: postgres
     restart: always
     environment:
       POSTGRES_USER: myuser
       POSTGRES_PASSWORD: mypassword
       POSTGRES_DB: mydb
     volumes:
        - ./data:/var/lib/postgresql/data

With which command should I execute it? and how do i create a yml file?

Those guies that you read didn’t explain the yaml syntax and the command to run the containers?

You need docker compose