0

I am using docker 1.9.1 and compose 1.6, I have am using the standard postgres container postgres:9.3.5 which has a data volume at /var/lib/postgresql/data I want to externally mount that file into /data which is a different disk ( not the root partition). I added the following to my compose file.

volumes:
 - /data/pg_data:/var/lib/postgresql/data


df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1       63G  5.9G   57G  10% /
devtmpfs        7.5G  120K  7.5G   1% /dev
tmpfs           7.5G     0  7.5G   0% /dev/shm
/dev/xvdb       985G  197M  934G   1% /data

starting the container results in my data volume not being present on /data. docker inspect reveals the following.

Mounts": [
        {
            "Source": "/data/pg_data",
            "Destination": "/var/lib/postgresql/data",
            "Mode": "rw",
            "RW": true
        }
    ]

if I use a symlink instead

/docker -> /data/pg_data 

and update the docker-compose file accordingly, it all works. The data is in the right place on /data

Any ideas whats going on?

jub0bs
  • 60,866
  • 25
  • 183
  • 186
Jeffrey Ellin
  • 586
  • 1
  • 3
  • 17
  • Instead of using `\`\`\`` guards, indent your code snippets by 4 spaces. – jub0bs Apr 18 '16 at 20:15
  • See also https://stackoverflow.com/questions/31747061/creating-a-docker-volume-at-a-specific-location –  Nov 25 '21 at 15:39

2 Answers2

0

Are you using VirtualBox? You can create a separate volume and mount it on the Postgres container:

$ docker volume create --name postgres_data

And in the docker-compose.yml:

version: "2"
  postgres:
    image:postgres:9.3.5
    ...
    volumes:
      - postgres_data:/var/lib/postgresql/data

volumes:
  postgres_data:
    external: true

You can mount the volume in another container and backup the data:

$ docker run -it -v postgres_data:/postgres_data $PWD:/backup alpine sh
$ cp -rf /postgres_data /backup/
0

I ended up upgrading docker to 1.9.1 and the problem went away. I couldn't find a bug in the docker release notes that sounds related but it definitely has fixed the issue on several machines.

Jeffrey Ellin
  • 586
  • 1
  • 3
  • 17