title: Mount linux image in docker container
body: <p>For a project I need to mount a linux image inside a docker container running <a href="https://hub.docker.com/_/ubuntu/" rel="noreferrer">ubuntu</a>. The image I want to mount is Raspbian. I need to access the linux filesystem of the image and add a file.</p>
  
  <p>I access the image by mounting the folder with the volume flag:</p>
  
  <p><code>docker run -it -v /path/to/image/folder:/default ubuntu /bin/bash</code></p>
  
  <p>With <code>fdisk -l raspbian.img</code> I found the offset:</p>
  
  <pre><code>Disk raspbian.img: 1.3 GiB, 1389363200 bytes, 2713600 sectors
  Units: sectors of 1 * 512 = 512 bytes
  Sector size (logical/physical): 512 bytes / 512 bytes
  I/O size (minimum/optimal): 512 bytes / 512 bytes
  Disklabel type: dos
  Disk identifier: 0x5a7089a1
  
  Device        Boot  Start     End Sectors  Size Id Type
  raspbian.img1        8192  137215  129024   63M  c W95 FAT32 (LBA)
  raspbian.img2      137216 2713599 2576384  1.2G 83 Linux
  </code></pre>
  
  <p>Now when I try to mount the image with <code>mount -o loop,offset=$((137216*512)) raspbian.img /mnt/</code> I get <code>mount: /mnt/: mount failed: Unknown error -1</code>. Can someone explain if I can mount a linux image in a running docker container and if so how?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Doing the same mount operations in vagrant works perfectly. Are there some limitations to docker mounting filesystems?</p>