Not able to access shared data volume

I have been trying to share data between my host and docker container. I am using this command to mount data volume:

sudo docker run -it -v /home/peeyush/Docker/docker/:/opt/test/:rw ubuntu /bin/bash

Now, when I run docker and try to access /opt/test/, it says I don’t have the permission. But I have already specified permission as read-write and I am root. Here is the output:

  • Move all Docker stuff?
  • How to play sound in a docker container
  • What is POSTGIS_VERSION 2.1.7+dfsg-3~94.git954a8d0.pgdg80+1?
  • Docker image seemingly having missing layers
  • Should I install Docker on Server Having Cpanel already on it?
  • How to access webserver running on localhost from a docker container on a network?
  • root@d61b3bfe0aab:/# ls /opt/test/
    ls: cannot open directory /opt/test/: Permission denied
    

    Any idea what am I doing wrong here?

    Update: Here is the output of ls -al /home/peeyush/Docker/docker:

    [peeyush@localhost docker]$ ls -al /home/peeyush/Docker/docker/
    total 308
    drwxrwxr-x. 29 peeyush peeyush  4096 Feb 24 14:14 .
    drwxrwxr-x.  5 peeyush peeyush  4096 Feb 23 15:38 ..
    drwxrwxr-x.  5 peeyush peeyush  4096 Feb 23 11:53 api
    -rw-rw-r--.  1 peeyush peeyush 28898 Feb 23 11:53 AUTHORS
    drwxrwxr-x.  4 peeyush peeyush  4096 Feb 23 11:53 builder
    drwxrwxr-x.  2 peeyush peeyush  4096 Feb 23 11:53 builtins
    drwxrwxr-x.  3 peeyush peeyush  4096 Feb 23 13:36 bundles
    -rw-rw-r--.  1 peeyush peeyush 61942 Feb 23 11:53 CHANGELOG.md
    drwxrwxr-x. 11 peeyush peeyush  4096 Feb 23 11:53 contrib
    -rw-rw-r--.  1 peeyush peeyush 13305 Feb 23 11:53 CONTRIBUTING.md
    drwxrwxr-x.  5 peeyush peeyush  4096 Feb 23 11:53 daemon
    drwxrwxr-x.  2 peeyush peeyush  4096 Feb 23 11:53 docker
    -rw-rw-r--.  1 peeyush peeyush  5423 Feb 24 14:14 Dockerfile
    -rw-rw-r--.  1 peeyush peeyush    16 Feb 23 11:53 .dockerignore
    drwxrwxr-x.  2 peeyush peeyush  4096 Feb 23 11:53 dockerinit
    drwxrwxr-x.  5 peeyush peeyush  4096 Feb 23 11:53 docs
    drwxrwxr-x.  2 peeyush peeyush  4096 Feb 23 11:53 engine
    drwxrwxr-x.  2 peeyush peeyush  4096 Feb 23 11:53 events
    drwxrwxr-x.  8 peeyush peeyush  4096 Feb 24 14:14 .git
    -rw-rw-r--.  1 peeyush peeyush   489 Feb 23 11:53 .gitignore
    drwxrwxr-x.  2 peeyush peeyush  4096 Feb 23 11:53 graph
    lrwxrwxrwx.  1 peeyush peeyush     7 Feb 23 11:53 hack -> project
    drwxrwxr-x.  3 peeyush peeyush  4096 Feb 23 11:53 image
    drwxrwxr-x.  3 peeyush peeyush  4096 Feb 23 11:53 integration
    drwxrwxr-x.  2 peeyush peeyush  4096 Feb 23 11:53 integration-cli
    -rw-rw-r--.  1 peeyush peeyush 10763 Feb 23 11:53 LICENSE
    drwxrwxr-x.  2 peeyush peeyush  4096 Feb 23 11:53 links
    -rw-rw-r--.  1 peeyush peeyush  7171 Feb 23 11:53 .mailmap
    -rw-rw-r--.  1 peeyush peeyush 18599 Feb 23 11:53 MAINTAINERS
    -rw-rw-r--.  1 peeyush peeyush  3400 Feb 23 11:53 Makefile
    drwxrwxr-x.  2 peeyush peeyush  4096 Feb 23 11:53 nat
    -rw-rw-r--.  1 peeyush peeyush   638 Feb 23 11:53 NOTICE
    drwxrwxr-x.  2 peeyush peeyush  4096 Feb 23 11:53 opts
    drwxrwxr-x. 39 peeyush peeyush  4096 Feb 23 11:53 pkg
    drwxrwxr-x.  3 peeyush peeyush  4096 Feb 23 11:53 project
    -rw-rw-r--.  1 peeyush peeyush 10624 Feb 23 11:53 README.md
    drwxrwxr-x.  3 peeyush peeyush  4096 Feb 23 11:53 registry
    drwxrwxr-x.  2 peeyush peeyush  4096 Feb 23 11:53 runconfig
    drwxrwxr-x.  2 peeyush peeyush  4096 Feb 23 11:53 trust
    drwxrwxr-x.  2 peeyush peeyush  4096 Feb 23 11:53 utils
    drwxrwxr-x.  3 peeyush peeyush  4096 Feb 23 11:53 vendor
    -rw-rw-r--.  1 peeyush peeyush    10 Feb 23 11:53 VERSION
    drwxrwxr-x.  2 peeyush peeyush  4096 Feb 23 11:53 volumes
    

    And of ls -al /opt/:

    root@d61b3bfe0aab:/# ls -al /opt/
    total 12
    drwxr-xr-x.  3 root root 4096 Feb 25 06:22 .
    drwxr-xr-x. 21 root root 4096 Feb 25 06:58 ..
    drwxrwxr-x. 29 1000 1000 4096 Feb 24 08:44 test
    

    Thanks.

  • Kubernetes access labels from containers
  • How to make communication between two docker containers running on two different hosts?
  • How do I make my docker image get custom argument at run command?
  • Docker DNS Error
  • Docker springboot app update war file without rebuilding using maven
  • How to install specific version of Docker on Centos?
  • 2 Solutions collect form web for “Not able to access shared data volume”

    Using a distro with SELinux? You can try turning it to passive (setenforce 0) or try a :Z/:z at the end of the -v command like (/home/peeyush/Docker/docker:/opt/test:Z)

    Would be interested to see if it works without the trailing ‘/’s on the directory paths, as I have never used them and never had this issue.

    sudo docker run -it -v /home/peeyush/Docker/docker:/opt/test ubuntu /bin/bash

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