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.

  • What is the exact difference between SizeRootFs and SizeRw in Docker containers?
  • Modifying 201-vmss-ubuntu-autoscale Azure quickstart template to include Docker extension
  • jenkins docker plugin job “Permission denied” error
  • How to view log4j logs running inside a docker container?
  • Can't start or list docker Machines created on another partition
  • managing multiple swarm clusters
  • 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 compose global level logging
  • How Docker calculates the hash of each layer? Is it deterministic?
  • Throttling Disk Utilization
  • Dockerized Spring Cloud Stream services with Kafka broker unable to connect to Zookeeper
  • How do I use Docker on cloud or datacenter
  • kubernetes loadbalancer with multiple backend ports
  • 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.