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:


version: '3.1'
     image: postgres
     restart: always
       POSTGRES_USER: myuser
       POSTGRES_PASSWORD: mypassword
       POSTGRES_DB: mydb
        - ./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