I can't access mounted volume of docker-postgres from host

I create my container like this:

docker run --name postgresql -itd --restart always \
--publish 5432:5432 \
--volume /my/local/host:/var/lib/postgresql \
sameersbn/postgresql:9.4-11

but, when I do ls on the root directory, I see something like this:

  • Configuring external access to the GAE app under the google/cloud-sdk docker container
  • Docker-compose depend_on
  • Docker nginx minitet
  • Schedule a container with docker swarm using gpu memory as a constraint
  • Setting DOCKER_HOST after Docker Toolbox/Mac install
  • docker run does not work from cronjob
  • drwxrwxr-x  3 messagebus messagebus 4,0K Ιαν  10 00:44 host/
    

    or, in other words, I cannot access the /my/local/host directory. I have no idea about the messagebus user. is that normal? if this is the case, then how could I move the database from one machine to another in the future?

  • Forwarding domains to docker containers
  • How to edit /etc/hosts file in running docker container
  • Invalid repository name while pulling an image in docker
  • YARN run MR job with DCE (docker container executor) stuck on ACCEPTED
  • How to install the latest Docker .deb package?
  • Docker - Initialize mysql database with schema
  • One Solution collect form web for “I can't access mounted volume of docker-postgres from host”

    Try using a data container to hold your DB data. The pattern is described in the docs and is designed to promote clean separation between run-time and data.

    $ docker create -v /var/lib/postgresql --name dbdata sameersbn/postgresql:9.4-11 
    $ docker run --name postgresql1 -itd --restart always \
    --publish 5432:5432 \
    --volumes-from dbdata
    sameersbn/postgresql:9.4-11
    

    A separate data container makes backup and recovery simpler and more obvious

    docker run --volumes-from dbdata -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar /var/lib/postgresql
    

    The following posting I think gives a good explanation of data containers:

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