Docker Volume another disk

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.

  • Programmatically setting Flash security in Linux
  • Docker container - how to configure so it gets a viable IP address when running in vagrant?
  • Migrating existing Docker containers to Docker Compose
  • docker-compose.yml vs docker-stack.yml what difference?
  • AppArmor deny all except one path
  • Cannot install packages inside docker Ubuntu image
  • 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?

  • Docker - Problems with the vocabs
  • How do I update Gemfile.lock on my Docker host?
  • How does one remove an image in Docker?
  • Is there a gui for writing dockerfiles?
  • How can I reproduce zombie process with bash as PID1 in docker?
  • “source” an 'sh' file for persistent variables in Docker
  • 2 Solutions collect form web for “Docker Volume another disk”

    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/
    

    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.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.