title: cat: "Permission denied" inside a docker container for existing file with proper permissions
body: <p>I'm new to docker and started with simple examples, but get "Permission denied":</p>
  
  <pre class="lang-sh prettyprint-override"><code>Gyro@Helper:~$ sudo docker run prakhar1989/static-site sh -c 'echo foo &gt; delete.me;echo bar &gt;&gt; delete.me;ls -l;type cat;ls -l /bin/cat;echo -n "I am ";whoami;cat delete.me'
  total 72
  drwxr-xr-x   2 root root 4096 Dec  4  2015 bin
  drwxr-xr-x   2 root root 4096 Aug 26  2015 boot
  -rw-r--r--   1 root root    8 Feb 15 15:38 delete.me
  drwxr-xr-x   5 root root  340 Feb 15 15:38 dev
  drwxr-xr-x   1 root root 4096 Feb 15 15:38 etc
  drwxr-xr-x   2 root root 4096 Aug 26  2015 home
  drwxr-xr-x   9 root root 4096 Nov 27  2014 lib
  drwxr-xr-x   2 root root 4096 Dec  4  2015 lib64
  drwxr-xr-x   2 root root 4096 Dec  4  2015 media
  drwxr-xr-x   2 root root 4096 Dec  4  2015 mnt
  drwxr-xr-x   2 root root 4096 Dec  4  2015 opt
  dr-xr-xr-x 271 root root    0 Feb 15 15:38 proc
  drwx------   2 root root 4096 Dec  4  2015 root
  drwxr-xr-x   3 root root 4096 Dec  4  2015 run
  drwxr-xr-x   2 root root 4096 Dec  4  2015 sbin
  drwxr-xr-x   2 root root 4096 Dec  4  2015 srv
  dr-xr-xr-x  13 root root    0 Dec 26 11:32 sys
  drwxrwxrwt   1 root root 4096 Dec 16  2015 tmp
  drwxr-xr-x   1 root root 4096 Jan  3  2016 usr
  drwxr-xr-x   1 root root 4096 Dec 16  2015 var
  -rwxr-xr-x   1 root root   69 Jan  3  2016 wrapper.sh
  cat is /bin/cat
  -rwxr-xr-x 1 root root 51912 Mar 14  2015 /bin/cat
  I am root
  cat: delete.me: Permission denied
  </code></pre>
  
  <p>The original problem was Permission denied on <code>wrapper.sh</code> so I played around a bit to get more information on the problem. </p>
  
  <p>The code and result above tells me that I can create a file named delete.me, append contents, see the file via ls, can check that cat is /bin/cat and has execute permission. I am logged in into the container as user root, but cat won't obey.</p>
  
  <p>Is it a bug?</p>
  
  <p><code>docker info</code> gives:</p>
  
  <pre><code>Gyro@Helper:~$ sudo docker info
  Containers: 38
   Running: 0
   Paused: 0
   Stopped: 38
  Images: 5
  Server Version: 18.09.9
  Storage Driver: overlay2
   Backing Filesystem: extfs
   Supports d_type: true
   Native Overlay Diff: true
  Logging Driver: json-file
  Cgroup Driver: cgroupfs
  Plugins:
   Volume: local
   Network: bridge host macvlan null overlay
   Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
  Swarm: inactive
  Runtimes: runc
  Default Runtime: runc
  Init Binary: docker-init
  containerd version: 894b81a4b802e4eb2a91d1ce216b8817763c29fb
  runc version: N/A
  init version: fec3683
  Security Options:
   apparmor
   seccomp
    Profile: default
  Kernel Version: 5.0.0-32-generic
  Operating System: Ubuntu Core 16
  OSType: linux
  Architecture: x86_64
  CPUs: 4
  Total Memory: 15.08GiB
  Name: x260
  ID: JCNS:55GU:FMFK:GJGF:JQ2P:IMSA:JOW2:JT5L:VQOB:QG4C:2NU5:Z6DR
  Docker Root Dir: /var/snap/docker/common/var-lib-docker
  Debug Mode (client): false
  Debug Mode (server): false
  Registry: https://index.docker.io/v1/
  Labels:
  Experimental: false
  Insecure Registries:
   127.0.0.0/8
  Live Restore Enabled: false
  
  WARNING: No swap limit support
  </code></pre>
  
  <p>Thanks to the help of @JohnKugelman it works now.
  Key thing is <em>not</em> to call</p>
  
  <p>sudo snap install docker</p>
  
  <p>but</p>
  
  <p><strong><em>sudo apt  install docker.io</em></strong></p>
  
  <pre><code>Gyro@Helper:~$ sudo snap remove docker
  docker removed
  Gyro@Helper:~$ sudo docker run prakhar1989/static-site sh -c 'echo foo &gt; delete.me;echo bar &gt;&gt; delete.me;ls -l;type cat;ls -l /bin/cat;echo -n "I am ";whoami;cp delete.me  newfile.del;ls -alrt'
  sudo: docker: command not found
  Gyro@Helper:~$ docker
  
  Command 'docker' not found, but can be installed with:
  
  sudo snap install docker     # version 18.09.9, or
  
  
  See 'snap info docker' for additional versions.
  
  Gyro@Helper:~$ sudo apt  install docker.io
  Reading package lists... Done
  (stuff deleted)
  Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
  Processing triggers for ureadahead (0.100.0-21) ...
  
  7[0;51r8[1A[JGyro@Helper:~$ 
  Gyro@Helper:~$ sudo docker run prakhar1989/static-site sh -c 'echo foo &gt; delete.me;echo bar &gt;&gt; delete.me;ls -l;type cat;ls -l /bin/cat;echo -n "I am ";whoami;cp delete.me  newfile.del;ls -alrt'
  Unable to find image 'prakhar1989/static-site:latest' locally
  latest: Pulling from prakhar1989/static-site
  
  (download progress deleted)
  total 72
  drwxr-xr-x   2 root root 4096 Dec  4  2015 bin
  drwxr-xr-x   2 root root 4096 Aug 26  2015 boot
  -rw-r--r--   1 root root    8 Feb 15 17:16 delete.me
  drwxr-xr-x   5 root root  340 Feb 15 17:16 dev
  drwxr-xr-x   1 root root 4096 Feb 15 17:16 etc
  drwxr-xr-x   2 root root 4096 Aug 26  2015 home
  drwxr-xr-x   9 root root 4096 Nov 27  2014 lib
  drwxr-xr-x   2 root root 4096 Dec  4  2015 lib64
  drwxr-xr-x   2 root root 4096 Dec  4  2015 media
  drwxr-xr-x   2 root root 4096 Dec  4  2015 mnt
  drwxr-xr-x   2 root root 4096 Dec  4  2015 opt
  dr-xr-xr-x 292 root root    0 Feb 15 17:16 proc
  drwx------   2 root root 4096 Dec  4  2015 root
  drwxr-xr-x   3 root root 4096 Dec  4  2015 run
  drwxr-xr-x   2 root root 4096 Dec  4  2015 sbin
  drwxr-xr-x   2 root root 4096 Dec  4  2015 srv
  dr-xr-xr-x  13 root root    0 Dec 26 11:32 sys
  drwxrwxrwt   1 root root 4096 Dec 16  2015 tmp
  drwxr-xr-x   1 root root 4096 Jan  3  2016 usr
  drwxr-xr-x   1 root root 4096 Dec 16  2015 var
  -rwxr-xr-x   1 root root   69 Jan  3  2016 wrapper.sh
  cat is /bin/cat
  -rwxr-xr-x 1 root root 51912 Mar 14  2015 /bin/cat
  I am root
  total 84
  drwxr-xr-x   9 root root 4096 Nov 27  2014 lib
  drwxr-xr-x   2 root root 4096 Aug 26  2015 home
  drwxr-xr-x   2 root root 4096 Aug 26  2015 boot
  drwxr-xr-x   2 root root 4096 Dec  4  2015 srv
  drwxr-xr-x   3 root root 4096 Dec  4  2015 run
  drwx------   2 root root 4096 Dec  4  2015 root
  drwxr-xr-x   2 root root 4096 Dec  4  2015 opt
  drwxr-xr-x   2 root root 4096 Dec  4  2015 mnt
  drwxr-xr-x   2 root root 4096 Dec  4  2015 media
  drwxr-xr-x   2 root root 4096 Dec  4  2015 lib64
  drwxr-xr-x   2 root root 4096 Dec  4  2015 bin
  drwxr-xr-x   2 root root 4096 Dec  4  2015 sbin
  drwxrwxrwt   1 root root 4096 Dec 16  2015 tmp
  drwxr-xr-x   1 root root 4096 Dec 16  2015 var
  -rwxr-xr-x   1 root root   69 Jan  3  2016 wrapper.sh
  drwxr-xr-x   1 root root 4096 Jan  3  2016 usr
  dr-xr-xr-x  13 root root    0 Dec 26 11:32 sys
  drwxr-xr-x   1 root root 4096 Feb 15 17:16 etc
  -rwxr-xr-x   1 root root    0 Feb 15 17:16 .dockerenv
  dr-xr-xr-x 290 root root    0 Feb 15 17:16 proc
  drwxr-xr-x   5 root root  340 Feb 15 17:16 dev
  -rw-r--r--   1 root root    8 Feb 15 17:16 delete.me
  -rw-r--r--   1 root root    8 Feb 15 17:16 newfile.del
  drwxr-xr-x   1 root root 4096 Feb 15 17:16 ..
  drwxr-xr-x   1 root root 4096 Feb 15 17:16 .
  Gyro@Helper:~$ sudo docker run prakhar1989/static-site sh -c 'echo foo &gt; delete.me;echo bar &gt;&gt; delete.me;ls -l;type cat;ls -l /bin/cat;echo -n "I am ";whoami;cat delete.me;ls -alrt'
  total 72
  drwxr-xr-x   2 root root 4096 Dec  4  2015 bin
  drwxr-xr-x   2 root root 4096 Aug 26  2015 boot
  -rw-r--r--   1 root root    8 Feb 15 17:17 delete.me
  drwxr-xr-x   5 root root  340 Feb 15 17:17 dev
  drwxr-xr-x   1 root root 4096 Feb 15 17:17 etc
  drwxr-xr-x   2 root root 4096 Aug 26  2015 home
  drwxr-xr-x   9 root root 4096 Nov 27  2014 lib
  drwxr-xr-x   2 root root 4096 Dec  4  2015 lib64
  drwxr-xr-x   2 root root 4096 Dec  4  2015 media
  drwxr-xr-x   2 root root 4096 Dec  4  2015 mnt
  drwxr-xr-x   2 root root 4096 Dec  4  2015 opt
  dr-xr-xr-x 291 root root    0 Feb 15 17:17 proc
  drwx------   2 root root 4096 Dec  4  2015 root
  drwxr-xr-x   3 root root 4096 Dec  4  2015 run
  drwxr-xr-x   2 root root 4096 Dec  4  2015 sbin
  drwxr-xr-x   2 root root 4096 Dec  4  2015 srv
  dr-xr-xr-x  13 root root    0 Dec 26 11:32 sys
  drwxrwxrwt   1 root root 4096 Dec 16  2015 tmp
  drwxr-xr-x   1 root root 4096 Jan  3  2016 usr
  drwxr-xr-x   1 root root 4096 Dec 16  2015 var
  -rwxr-xr-x   1 root root   69 Jan  3  2016 wrapper.sh
  cat is /bin/cat
  -rwxr-xr-x 1 root root 51912 Mar 14  2015 /bin/cat
  I am root
  foo
  bar
  total 80
  drwxr-xr-x   9 root root 4096 Nov 27  2014 lib
  drwxr-xr-x   2 root root 4096 Aug 26  2015 home
  drwxr-xr-x   2 root root 4096 Aug 26  2015 boot
  drwxr-xr-x   2 root root 4096 Dec  4  2015 srv
  drwxr-xr-x   3 root root 4096 Dec  4  2015 run
  drwx------   2 root root 4096 Dec  4  2015 root
  drwxr-xr-x   2 root root 4096 Dec  4  2015 opt
  drwxr-xr-x   2 root root 4096 Dec  4  2015 mnt
  drwxr-xr-x   2 root root 4096 Dec  4  2015 media
  drwxr-xr-x   2 root root 4096 Dec  4  2015 lib64
  drwxr-xr-x   2 root root 4096 Dec  4  2015 bin
  drwxr-xr-x   2 root root 4096 Dec  4  2015 sbin
  drwxrwxrwt   1 root root 4096 Dec 16  2015 tmp
  drwxr-xr-x   1 root root 4096 Dec 16  2015 var
  -rwxr-xr-x   1 root root   69 Jan  3  2016 wrapper.sh
  drwxr-xr-x   1 root root 4096 Jan  3  2016 usr
  dr-xr-xr-x  13 root root    0 Dec 26 11:32 sys
  drwxr-xr-x   1 root root 4096 Feb 15 17:17 etc
  -rwxr-xr-x   1 root root    0 Feb 15 17:17 .dockerenv
  dr-xr-xr-x 289 root root    0 Feb 15 17:17 proc
  drwxr-xr-x   5 root root  340 Feb 15 17:17 dev
  -rw-r--r--   1 root root    8 Feb 15 17:17 delete.me
  drwxr-xr-x   1 root root 4096 Feb 15 17:17 ..
  drwxr-xr-x   1 root root 4096 Feb 15 17:17 .
  Gyro@Helper:~$ sudo docker run --rm prakhar1989/static-site
  Nginx is running...
  </code></pre>