How do I copy a file from host into a LXD container?

I have a file on the host that I want to copy into the LXD container.

What is the command to copy the host -> container?

You need to use the lxc file push subcommand, to push a file from the host to a container.
For example,

lxc file push myfile.txt mycontainer/home/ubuntu/

The destination starts with the container name (mycontainer), and then you append the path (/home/ubuntu/) in my example. Note that you need to put a final / if you want to put a file in a directory, else you get an error.

More at


Is it possible to do this remotely? I need to copy folders from my computer to the container host and then into the container. I can do this is two steps, like rsync to the container host, then lxc push to the container. Is there a better way to accomplish what Iā€™m trying? Thanks for any tips.


lxc is a client, and can manage any LXD server (a remote) that you have configured.
To see the list of currently available servers, run the following

lxc remote list

The one called local (default), is your local LXD server. The others, such as ubuntu: and images: are repositories of container and VM images. Those two only serve images and are read-only.

What you can do, is

  1. configure your remote LXD server to be accessible remotely over the network
  2. configure your local lxc client to be able to also manage that remote LXD server of yours.

On the remote LXD server, run the following. Please change mypassword to something really long and unpredictable.

lxc config set core.https_address [::]:8443
lxc config set core.trust_password mypassword

On the local system, run the following. You will be prompted to type the password that you configured on the LXD server earlier. myserver is just a mnemonic for your remote LXD server.

lxc remote add myserver hostname_or_IP_of_LXD_server

Having done that, you can now do the following. That is, the same LXD commands, but you prepend myserver: to specify the remote LXD server.

lxc list myserver:
lxc shell myserver:mycontainer
lxc file push myfile.txt myserver:mycontainer/home/ubuntu/
1 Like