Linux Containers (LXC) with LXD Hypervisor, Part 3 : Transferring Files Between Host and Container

Other articles in the series:
In this part 3, we're going to explore on how to copy file(s) from the host to the container and vice versa. Copying file from the host to the container is simply just using the 'lxc file push <filename> <container-name>/' command. You must append a forward slash (/), to indicate a directory name to the container name for it to work as shown below.
$ echo "a" > foobar
$ md5sum foobar 
60b725f10c9c85c70d97880dfe8191b3  foobar
$ lxc file push foobar test-centos-6
error: Invalid target test-centos-6
$ lxc file push foobar test-centos-6/tmp
error: exit status 255: mntns dir: /proc/16875/ns/mnt
open container: Is a directory

$ lxc file push foobar test-centos-6/tmp

Similarly, the copy file from container, just use the 'lxc file pull <container-name>/ <filename> .' command. Remember to put the dot (.) which indicates the destination or current folder.
$ lxc file pull test-centos-6/tmp/foobar .
$ md5sum foobar
60b725f10c9c85c70d97880dfe8191b3  foobar

As LXC is actually a glorify chroot environment container. You can actually create or copy files or folders from and to the chroot directory directly.
$ cd /var/lib/lxd/containers/test-centos-6/rootfs/tmp
$ touch create_file_directly_in_chroot_folder

Repeat the similar steps but in the container.
$ lxc exec test-centos-6 /bin/bash
$ cd /tmp
$ touch create_file_directly_in_container

Checking these files from the host. Note the file permissions.
$ ll /var/lib/lxd/containers/test-centos-6/rootfs/tmp/
total 0
-rw-rw-r-- 1 ang    ang    0 Sep  29 02:00 create_file_directly_in_chroot_folder
-rw-r--r-- 1 100000 100000 0 Sep  29 02:00 create_file_directly_in_container

Similarly, but inside the LXC container.
[[email protected] tmp]# ll
total 0
-rw-rw-r-- 1 65534 65534 0 Sep 28 14:00 create_file_directly_in_chroot_folder
-rw-r--r-- 1 root  root  0 Sep 28 14:00 create_file_directly_in_container

While this is doable, we shouldn't create files or folders directly in the container chroot folder from the host. Use the 'lxc push' and 'lxc pull' command to preserve the file permissions.

Installation and Usage of R, The Statistical Computing Language and Environment

One of the interesting thing that piqued my interest for the past two weeks was picking up R, "a language and environment for statistical computing and graphics.". For me, is just another great graphing tool, in addition to Gnuplot (more on this in future post), to plot graph from the console. To be frank, I really like R, easy to pick up (feels like PHP), and plenty of available resources in term of books and search results.

Why R? Few months back, I've bought a Pedometer and starts to capture my daily steps count in CSV format. Instead of putting these data in Google Sheet, I opted to put this in GitHub instead. First, it allows me to build a habit of making daily commits to GitHub. Second, I can explore different kind of graphical plotting tools. Lastly, which is the most important one, it let me have a general overview and awareness of my sedentary lifestyle over a period. This help me to make necessary adjustment which will affect my health. You can't make any changes if you're not constantly aware of the issue, face it directly, and make the necessary changes.

Installation in Ubuntu, in my case, 15.04 is pretty much straight forward.
$ sudo apt-get install r-base

Next, let's start R (yes, capital R) and plot a simple graph.
$ R

R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> x <- c(1,2,3)
> y <- c(10,20,30)
> plot(x,y)

The above code will produce the following graph.

Instead of generating the graph through the R interpreter, we can also generate it in batch mode using the 'Rscript' command. Create a new file called 'plot.R' with the follow code. After you've compile it, a PDf file named Rplots.pdf will be generated with the graph.
$ cat plot.R
x <- c(1,2,3)
y <- c(10,20,30)

If we need to install any packages, use this command below. Note that this is through the console.
$ sudo Rscript -e "install.packages('ggplot2', repos='')"

Similarly, If you want to install it through the R interpreter.
> install.packages('ggplot2', repos='')

Or without specifying the repository. You will be prompted for one.
> install.packages('ggplot2')

Having done these steps, it should be sufficient enough to explore more powerful features of R. Have fun!