Postgres: Data volume empty on host machine

Created on 6 Aug 2018  路  4Comments  路  Source: docker-library/postgres

Hi everyone,

Same issue as https://stackoverflow.com/questions/41637505/how-to-persist-data-in-a-dockerized-postgres-database-using-volumes

When I mount my data volume, it remains empty in my host. Using /var/lib/postgresql/data instead /var/lib/postgresql does not helps. Giving 755 permission on whole data directory finally share files, but why and how to make it working with default access ?

docker-compose version 1.17.0, build ac53b73
docker-py version: 2.5.1
CPython version: 2.7.13
OpenSSL version: OpenSSL 1.0.1t  3 May 2016
Client:
 Version:       18.03.0-ce
 API version:   1.37
 Go version:    go1.9.4
 Git commit:    0520e24
 Built: Wed Mar 21 23:10:01 2018
 OS/Arch:       linux/amd64
 Experimental:  false
 Orchestrator:  swarm

Server:
 Engine:
  Version:      18.03.0-ce
  API version:  1.37 (minimum version 1.12)
  Go version:   go1.9.4
  Git commit:   0520e24
  Built:        Wed Mar 21 23:08:31 2018
  OS/Arch:      linux/amd64
  Experimental: false
services:
  test_postgres:
    container_name: test_postgres
    environment:
      POSTGRES_DB: weeha
      POSTGRES_PASSWORD: weehe
      POSTGRES_USER: wooho
    image: postgres:10.4
    restart: always
    volumes:
    - ./data:/var/lib/postgresql/data:rw
version: '2.0'

Steps to reproduce the issue

  1. Use the given docker-compose.yml
  2. run docker-compose up -d
  3. run ls -la ./data
  4. run docker exec -ti test_postgres ls -la /var/lib/postgresql/data

Observed result

./data is empty
/var/lib/postgresql/data is not empty

Expected result

./data and /var/lib/postgresql/data should have the same contents

Additional information

Ubuntu 16.x

question

Most helpful comment

version: "2"

services:
  test_postgres:
    container_name: test_postgres
    environment:
      POSTGRES_DB: weeha
      POSTGRES_PASSWORD: weehe
      POSTGRES_USER: wooho
    image: postgres:10.4
    restart: always
    volumes:
            - ./data:/var/lib/postgresql/data:rw
# ls
docker-compose.yml
# docker-compose up -d
WARNING: The Docker Engine you're using is running in swarm mode.

Compose does not use swarm mode to deploy services to multiple nodes in a swarm. All containers will be scheduled on the current node.

To deploy your application across the swarm, use `docker stack deploy`.

Creating network "postgres-476_default" with the default driver
Creating test_postgres ... done
# ls
data/  docker-compose.yml
# sudo ls data
base           pg_logical    pg_stat      pg_wal
global         pg_multixact  pg_stat_tmp  pg_xact
pg_commit_ts   pg_notify     pg_subtrans  postgresql.auto.conf
pg_dynshmem    pg_replslot   pg_tblspc    postgresql.conf
pg_hba.conf    pg_serial     pg_twophase  postmaster.opts
pg_ident.conf  pg_snapshots  PG_VERSION   postmaster.pid

I'm not able to reproduce

All 4 comments

version: "2"

services:
  test_postgres:
    container_name: test_postgres
    environment:
      POSTGRES_DB: weeha
      POSTGRES_PASSWORD: weehe
      POSTGRES_USER: wooho
    image: postgres:10.4
    restart: always
    volumes:
            - ./data:/var/lib/postgresql/data:rw
# ls
docker-compose.yml
# docker-compose up -d
WARNING: The Docker Engine you're using is running in swarm mode.

Compose does not use swarm mode to deploy services to multiple nodes in a swarm. All containers will be scheduled on the current node.

To deploy your application across the swarm, use `docker stack deploy`.

Creating network "postgres-476_default" with the default driver
Creating test_postgres ... done
# ls
data/  docker-compose.yml
# sudo ls data
base           pg_logical    pg_stat      pg_wal
global         pg_multixact  pg_stat_tmp  pg_xact
pg_commit_ts   pg_notify     pg_subtrans  postgresql.auto.conf
pg_dynshmem    pg_replslot   pg_tblspc    postgresql.conf
pg_hba.conf    pg_serial     pg_twophase  postmaster.opts
pg_ident.conf  pg_snapshots  PG_VERSION   postmaster.pid

I'm not able to reproduce

Given that we can't reproduce, I'm afraid to say this is likely something environmental (not an issue in the image itself which we could fix).

For further help troubleshooting, I'd recommend trying the Docker Community Forums, the Docker Community Slack, or Stack Overflow.

Hi @weeger were you able to resolve this issue?

i had the same problem. These steps helped me:
1) mount data folder as wglambert wrote.
2) add postgres user into the host with the same id group and user, otherwise postgres have no permissions to write files on your host

Was this page helpful?
0 / 5 - 0 ratings