1

Mac OS 10.13.6 docker 9.03.5, build 633a0ea

I create two docker containers, web and db using docker-compose.yml. It worked for several months. Recently I decided to rebuild containers from scratch, so I actually removed the existing ones and started over:

$ docker-compose  -f docker-compose-dev.yml build --no-cache
$ docker-compose  -f docker-compose-dev.yml up -d

Duiring the "build" run, building db container yields this:

DETAIL: The data directory was initialised by PostgreSQL version 9.6, which is not compatible with this version 11.2.

exited with code 1

The db container does not start so I can not check what it's got inside.

My containers are defined like this:

version: '3'

services:
  web:
    restart: unless-stopped
    container_name: web
    build:
      context: .
      dockerfile: Dockerfile.dev
    ports:
      - "8000:8000"
    environment:
      DJANGO_SETTINGS_MODULE: '<my_app>.settings.postgres'
      DB_NAME: 'my_db'
      DB_USER: 'my_db_user'
      DB_PASS: 'my_db_user'
      DB_HOST: 'my_db_host'
      PRODUCTION: 'false'
      DEBUG: 'True'
    depends_on:
      - db
    volumes:
      - ./:/usr/src/app/
  db:
    image: postgres:11.2-alpine
    volumes:
      - myapp-db-dev:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=<my_db>
      - POSTGRES_USER=<my_db_user>
      - POSTGRES_PASSWORD=<my_db_password>
volumes:
  myapp-db-dev:

My local postgresql is 11.3 (which should be irrelevant):

$ psql --version
psql (PostgreSQL) 11.3

and my local postgresql data directory was removed completely

$ rm -rf /usr/local/var/postgres

However, it's up-to-date:

$ brew postgresql-upgrade-database
Error: postgresql data already upgraded!

I read Stack Overflow 17822974 and Stack Overflow 19076980, those advices did not help.

How to fix this data incompatibility? If possible, I would like to avoid downgrading postgres. I don't even get what data it's talking about at that point, all the data is migrated later in a separate step.

1 Answer 1

1

It seems like on the first run Postgres 9.6 was specified as an image. So, the container was initialized and the data was put to the myapp-db-dev named volume. Then someone changed the version and you've got the error. The possible solution would be:

  1. Temporary downgrade the version to the Postgres 9.6, e.g. specify postgres:9.6.
  2. Go to the container and dump the data with pg_dump utility.
  3. Change version to 11.2 and specify new volume (it's a good advice to use host volume).
  4. Restore the data.
Sign up to request clarification or add additional context in comments.

2 Comments

What's pg_data ? Maybe pg_dump ? Could you elaborate on "specify new volume" please? Curenty in db container of my docker-compose.yml I have - data:/var/lib/postgresql/data, should I replace it with something else? With what?
@SwissNavy yes, it should be pg_dump. Yes, for example with ./mydata: /var/lib/postgresql/data, but check twice that you properly backed up your data.

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.