1

I am trying to copy a file with lxc, now I am already desperate. Here are some commands that I have tried:

#temp=$(cat 2.sh)
#lxc-attach -n containerName echo $temp > /root/2.sh
#lxc-attach -n containerName cat /root/2.sh
->

#temp=$(cat 2.sh)
#lxc-attach -n containerName -- bash -c 'echo $temp > /root/2.sh'
#lxc-attach -n containerName cat /root/2.sh
->

#lxc-attach -n containerName -- bash -c 'echo $(cat 2.sh) > /root/2.sh'
->cat: 2.sh: No such file or directory

#lxc-attach -n containerName -- bash -c 'echo "$(cat 2.sh)" > /root/2.sh'
->cat: 2.sh: No such file or directory


#lxc file push 2.sh containerName/root/
->Error: not found

The -> is the output

Containers are built with lxc- and do not appear in the lxc list list, but in the lxc-ls list.

Any help is welcome

ICIM
  • 150
  • 1
  • 9

2 Answers2

1

Try this:

cat 2.sh | lxc-attach -n containerName tee /root/2.sh

Note:

I tested this with docker containers, as I don't have lxc available at the moment. With docker this works when the -i parameter for an interactive session is specified. I don't see a corresponding parameter for lxc-attach, I don't know if this is necessary or possible.

Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
  • Well, the truth is that no, if they don't have the format indicated above directly, they don't work. But +1 for teaching me how to do that in docker. I leave an example `cat 2.sh | docker exec -i name_container tee /root/2.sh` – ICIM Jul 23 '21 at 16:50
0

This solution only works in the case that the LXC is in a machine in which you can connect with SSH, DOES NOT WORK WITH VIRTULIZED LXC. You need access to the lxc folders!

cp /root/input/2.sh /var/lib/lxc/NAME_LXC/rootfs/root/2.sh

The truth is that it is a mess for me to understand LXC/LXD. Now I understand many things and it became clearer to me how it works from behind

The trick is that everything is based on physical files in this path /var/lib/lxc/

ICIM
  • 150
  • 1
  • 9