0

Not sure why, my docker compose file is:

services:
  db:
    image: "postgres:latest"
    ports:
      - "5432:5432"
    volumes:
      - ods:/var/postgresql/data
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=ods

volumes:
  ods:

when I do docker volume ls I can see the line

local postgres_ods

has been created (not sure why it has added postgres_ to the front)

I will then create a table, save it, commit it, add some data to it.

do a docker compose down then a docker compose up -d

I find that the data and the table has gone missing.

inspecting postgres_ods gives me:

[
    {
        "CreatedAt": "2021-11-17T00:26:15Z",
        "Driver": "local",
        "Labels": {
            "com.docker.compose.project": "postgres",
            "com.docker.compose.version": "2.0.0",
            "com.docker.compose.volume": "ods"
        },
        "Mountpoint": "/var/lib/docker/volumes/postgres_ods/_data",
        "Name": "postgres_ods",
        "Options": null,
        "Scope": "local"
    }
]

what am I doing wrong?

1 Answer 1

1

Wrong folder mapped, that is why the data didn't stick around:

version: "3.9"
services:
  db:
    image: "postgres:latest"
    ports:
      - "5432:5432"
    volumes:
      - ods:/var/lib/postgresql/data
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=ods

volumes:
  ods:
Sign up to request clarification or add additional context in comments.

1 Comment

As James said - the volume path must be correct. If you are using a different postgres image like the bitnami one - make sure you use the right path (/bitnami/postgresql).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.