D
D
Denis2021-12-24 15:15:21
Docker
Denis, 2021-12-24 15:15:21

Docker on windows not working volumes?

Help with the docker to understand if anyone is in the subject. In general, he collected the config for understanding. As a result, everything seems to work, but it does not save data in postgres. More precisely, here's what's going on.

  • docker-compose up --build -d
  • I create a migration model from it, and roll the migration into the database (symphony), then upload the fake data to the database and see everything perfectly. There are tables, there are data in them.
  • worked, I write docker-compose down turned off the pc
  • I turned on the PC, I write docker-compose up --build -d containers rise the base is empty

Although I wrote this in the docker-compose config
postgres:
    container_name: symfony-postgres
    image: postgres:12
    volumes:
      - ./docker/postgres:/var/lib/postgres
    restart: always
    environment:
        POSTGRES_DB: db
        POSTGRES_USER: user
        POSTGRES_PASSWORD: secret
    ports:
        - 15432:5432

and at the very bottom
volumes:
  postgres:

but the folder on the host ./docker/postgres is empty
, although I looked in Mounts there is such an entry
"Mounts": [
            {
                "Type": "bind",
                "Source": "E:\\projects\\repo\\docker\\postgres",
                "Destination": "/var/lib/postgres",
                "Mode": "rw",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Type": "volume",
                "Name": "ded9c7006aa1cd122783b4fb0503fe97e6b6180ddc68885184e3e4e4c75d999f",
                "Source": "/var/lib/docker/volumes/ded9c7006aa1cd122783b4fb0503fe97e6b6180ddc68885184e3e4e4c75d999f/_data",
                "Destination": "/var/lib/postgresql/data",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            }
        ],

here "E:\\projects\\repo\\docker\\postgres"
points to the folder that I specified in volumes
volumes:
- ./docker/postgres:/var/lib/postgres

but there is nothing in it...
maybe someone in the course of what to look there why it does not work? Well, as you guessed, it's all on windows.

PS
I previously had a
volumes entry:
- postgres:/var/lib/postgres
and maunts showed that Source is located at "Source": "/var/lib/docker/volumes/repo_postgres/_data",
but I have Windows )) where does /var come from?

looked in the docker folder on Windows there is no volumes
looked in Ubuntu wsl there is not even a docker there))

well, that's right, by the way...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
KoreanGuy, 2021-12-25
@Drumsid

since you are explicitly specifying a directory on the host, this is not a volume, but a bind mount. When using bind mount, the config section volumes(at the top level) is not needed. You can delete it. Moreover, you still write it incorrectly. But you don’t have files, because you are specifying the wrong directory in the container. Need /var/lib/postgres ql /data

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question