LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Virtualization and Cloud (https://www.linuxquestions.org/questions/linux-virtualization-and-cloud-90/)
-   -   Docker volume mount of .img file (https://www.linuxquestions.org/questions/linux-virtualization-and-cloud-90/docker-volume-mount-of-img-file-4175731367/)

Micah 11-29-2023 03:35 PM

Docker volume mount of .img file
 
I was looking for a simple way to archive a large set of small files and not letting size go crazy. If this works, I would just copy a single file as an archive vs spending hours sync'ing the files to a backup location.

From my research, my issue has something to do with the /dev/loop0 but from what I've seen they all say mount it first, then use it. Several try to create the loop in the container, but then you have to create the /dev entries. I'd rather leave that out of the container and let the host deal with it.

I'm trying to map a volume in my docker-compose.yaml, but it never appears in the container...

On the Host
Code:

truncate -s 5G /srv/myimage.img 
mkfs.btrfs /srv/myimage.img
mount -o loop,discard,compress=lzo /srv/myimage.img /mnt/myimage/

The container (docker-compose snippet):
(I'm using version: '2' but I can use any version if needed.)
Code:

  app:
    build: dockerfolder
    container_name: myContainer
    network_mode: bridge
    restart: unless-stopped
    privileged: true
    device_cgroup_rules:
      - b 7:* rmw
    volumes:
      - /dev:/dev
      - /mnt/myimage:/data

I run this:
Code:

docker-compose exec app bash
df -h

but my volume doesn't appear. If I attempt to use it, it dumps the data to a folder on /mnt/myimage (of the host drive - you have to unmount the img to see it)


All times are GMT -5. The time now is 02:21 AM.