Copying file to HostOS and accessing it inside the container

Hello,

Till now I have recognized that bind mounts are not allowed with balena, and you can read only limited folders like /sys and /proc etc. by setting the corresponding label or running the container in privileged mode: Multiple containers - Balena Documentation

What I want to achieve is create a file with certain config parameters on host, which I can then read inside the container. However, when I try to create a new folder or file in /sys folder of the host, it doesn’t allow me to create, either saying permission denied or read-only file system.

Is there any alternate way through which I can create a file on host at any location and then read the file from inside the container?

Thank you.

Regards,
Muhammad

Hi Muhammad
Welcome to the forums! I hope we’ll be able to help you. It looks like you’re on the right track about sharing files among containers, and with the host.
I’ve created a sample app that follows what’s described on Multiple containers - Balena Documentation , creating a named volume shared by - in my example - two containers, and then being able to create a file from hostOS and then see it from the containers.

here’s the example docker-compose.yml:

version: "2.1"

volumes:
    mydata:

services:
  test1:
    image: balenalib/intel-nuc-ubuntu-node:16-bionic
    entrypoint: ["tail", "-f", "/dev/null"]
    volumes:
      - 'mydata:/mydata'        
  test2:
    image: balenalib/intel-nuc-ubuntu-node:16-bionic
    entrypoint: ["tail", "-f", "/dev/null"]
    volumes:
      - 'mydata:/mydata'        

The key to accessing the folder from the hostOS is using this template for the folder name /var/lib/docker/volumes/<FLEET ID>_resin-data/_data.

In my case, from hostOS, after I deployed the app:

root@29eba2b:~# ls -l /var/lib/docker/volumes/
total 48
drwx-----x 3 root root  4096 Dec 16 16:59 1949587_mydata
-rw------- 1 root root 65536 Dec 16 16:59 metadata.db
root@29eba2b:~# ls -l /var/lib/docker/volumes/1949587_mydata/
total 4
drwxr-xr-x 2 root root 4096 Dec 16 16:59 _data
root@29eba2b:~# ls -l /var/lib/docker/volumes/1949587_mydata/_data/
total 0
root@29eba2b:~# touch /var/lib/docker/volumes/1949587_mydata/_data/README.txt

and then from one of the containers:

root@36e73cd78dbd:/# ls -l /mydata
total 0
-rw-r--r-- 1 root root 0 Dec 16 17:02 README.txt

Hope this helps, let me know if you have any further questions.

Ramiro