Share file written in container with host OS


#1

I am new to contianers and I am sure this is a stupid question that has an easy answer. I just couldnt find that easy answer.
I created a file in my container and I want to edit it in my host.
How???
Thanks


#2

Hi!

You can either copy it from the container to the host (pull), edit on the host (and perhaps copy back to the container(push)). You do this with the lxc file command, and obviously you run these commands from the host. For example,

lxc file pull mycontainer/home/ubuntu/myfile.txt /tmp/
nano /tmp/myfile.txt
lxc file push /tmp/myfile.txt mycontainer/home/ubuntu/

Note that when you use lxc file, the mycontainer/home/ubuntu/myfile.txt is made of your container name (mycontainer) and the full path of the file/directory (/home/ubuntu/myfile.txt).
In addition, when you copy to a directory on the container, you have to write mycontainer/home/ubuntu/ instead of mycontainer/home/ubuntu.

The other way is to bind-mount a directory from the host to the container. Then, anything you put in that directory will be visible at the same time on the host.


(Stéphane Graber) #3

lxc file edit also does all 3 steps for you


#4

Thanks for this.
Just to be clear
even though mycontainer is located at /var/lib/lxc/mycontainer
I only need to run
$ lxc file pul mycontainer/home/ununtu/myfile.txt /tmp/
and myfile.txt is copied to /tmp/ on the host.


#5

thank you.
i’ll give it a go