Sunday, December 28, 2014

export docker image to use with lxc

1- we will export image ubuntu 14.04 from docker to use with lxc

2- list docker image
root@lxc-docker:/# docker.io images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu              15.04               6810a8f874dd        12 days ago         116.9 MB
ubuntu              vivid               6810a8f874dd        12 days ago         116.9 MB
ubuntu              14.10               faf7a9358af7        12 days ago         199.2 MB
ubuntu              utopic              faf7a9358af7        12 days ago         199.2 MB
ubuntu              latest              04c5d3b7b065        12 days ago         192.7 MB
ubuntu              14.04               04c5d3b7b065        12 days ago         192.7 MB
ubuntu              14.04.1             04c5d3b7b065        12 days ago         192.7 MB
ubuntu              trusty              04c5d3b7b065        12 days ago         192.7 MB
ubuntu              12.04.5             f7653ea50b9b        12 days ago         130.3 MB
ubuntu              precise             f7653ea50b9b        12 days ago         130.3 MB
ubuntu              12.04               f7653ea50b9b        12 days ago         130.3 MB
nginx               1                   e46b3488b010        3 weeks ago         91.88 MB
nginx               1.7                 e46b3488b010        3 weeks ago         91.88 MB
nginx               1.7.8               e46b3488b010        3 weeks ago         91.88 MB
nginx               latest              e46b3488b010        3 weeks ago         91.88 MB
centos              centos5             6cc180b1c73b        3 weeks ago         466.9 MB
centos              centos6             25c5298b1a36        3 weeks ago         215.8 MB
centos              centos7             34943839435d        3 weeks ago         224 MB
centos              latest              34943839435d        3 weeks ago         224 MB
nginx               1.7.7               3535cfc9f3ea        3 weeks ago         100.2 MB
nginx               1.7.6               561ed4952ef0        9 weeks ago         100.2 MB
nginx               1.7.5               d2d79aebd368        3 months ago        100.2 MB
nginx               1.7.1               61e8f94e1d65        5 months ago        499.1 MB
ubuntu              quantal             c5881f11ded9        6 months ago        172.2 MB
ubuntu              12.10               c5881f11ded9        6 months ago        172.2 MB
ubuntu              raring              463ff6be4238        6 months ago        169.4 MB
ubuntu              13.04               463ff6be4238        6 months ago        169.4 MB
ubuntu              saucy               195eb90b5349        6 months ago        184.7 MB
ubuntu              13.10               195eb90b5349        6 months ago        184.7 MB
ubuntu              10.04               3db9c44f4520        8 months ago        183 MB
ubuntu              lucid               3db9c44f4520        8 months ago        183 MB


3- export ubuntu 14.04 to a file ubuntu.rar
root@lxc-docker:/# docker.io save ubuntu:14.04 > ubuntu.tar

4-  list content in the ubuntu.tar archive

root@lxc-docker:/# tar tvf ubuntu.tar
drwx------ 0/0               0 2014-12-28 12:50 ./
drwxr-xr-x 0/0               0 2014-12-28 12:50 511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/
-rw-r--r-- 0/0               3 2014-12-28 12:50 511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/VERSION
-rw-r--r-- 0/0             645 2014-12-28 12:50 511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/json
-rw-r--r-- 0/0            1536 2014-12-28 12:50 511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/layer.tar
drwxr-xr-x 0/0               0 2014-12-28 12:50 70c8faa62a44b9f6a70ec3a018ec14ec95717ebed2016430e57fec1abc90a879/
-rw-r--r-- 0/0               3 2014-12-28 12:50 70c8faa62a44b9f6a70ec3a018ec14ec95717ebed2016430e57fec1abc90a879/VERSION
-rw-r--r-- 0/0            2673 2014-12-28 12:50 70c8faa62a44b9f6a70ec3a018ec14ec95717ebed2016430e57fec1abc90a879/json
-rw-r--r-- 0/0          226304 2014-12-28 12:50 70c8faa62a44b9f6a70ec3a018ec14ec95717ebed2016430e57fec1abc90a879/layer.tar
drwxr-xr-x 0/0               0 2014-12-28 12:50 c7b7c64195686444123ef370322b5270b098c77dc2d62208e8a9ce28a11a63f9/
-rw-r--r-- 0/0               3 2014-12-28 12:50 c7b7c64195686444123ef370322b5270b098c77dc2d62208e8a9ce28a11a63f9/VERSION
-rw-r--r-- 0/0            1503 2014-12-28 12:50 c7b7c64195686444123ef370322b5270b098c77dc2d62208e8a9ce28a11a63f9/json
-rw-r--r-- 0/0       201575936 2014-12-28 12:50 c7b7c64195686444123ef370322b5270b098c77dc2d62208e8a9ce28a11a63f9/layer.tar
drwxr-xr-x 0/0               0 2014-12-28 12:50 d735006ad9c1b1563e021d7a4fecfd75ed36d4384e2a1c42e78d8261b83d6271/
-rw-r--r-- 0/0               3 2014-12-28 12:50 d735006ad9c1b1563e021d7a4fecfd75ed36d4384e2a1c42e78d8261b83d6271/VERSION
-rw-r--r-- 0/0            1478 2014-12-28 12:50 d735006ad9c1b1563e021d7a4fecfd75ed36d4384e2a1c42e78d8261b83d6271/json
-rw-r--r-- 0/0            6656 2014-12-28 12:50 d735006ad9c1b1563e021d7a4fecfd75ed36d4384e2a1c42e78d8261b83d6271/layer.tar
drwxr-xr-x 0/0               0 2014-12-28 12:50 ubuntu:14.04/
-rw-r--r-- 0/0               3 2014-12-28 12:50 ubuntu:14.04/VERSION
-rw-r--r-- 0/0            1441 2014-12-28 12:50 ubuntu:14.04/json
-rw-r--r-- 0/0            3072 2014-12-28 12:50 ubuntu:14.04/layer.tar


5- create a directory can ubuntu-14.04 and extract all */layer.tar to the direcotry
root@lxc-docker:/# mkdir ubuntu-14.04
root@lxc-docker:/# cd  ubuntu-14.04
root@lxc-docker:/# tar xvf ../511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/layer.tar
root@lxc-docker:/# tar xvf ../70c8faa62a44b9f6a70ec3a018ec14ec95717ebed2016430e57fec1abc90a879/layer.tar
root@lxc-docker:/# tar xvf ../c7b7c64195686444123ef370322b5270b098c77dc2d62208e8a9ce28a11a63f9/layer.tar
root@lxc-docker:/# tar ../xvfd735006ad9c1b1563e021d7a4fecfd75ed36d4384e2a1c42e78d8261b83d6271/layer.tar
root@lxc-docker:/# tar xvf ../ubuntu:14.04/layer.tar


6- create rootfs cache for lxc by copy the directory to /var/cache/lxc/trusty/
root@lxc-docker:/# cp ubuntu-14.04 /var/cache/lxc/trusty/rootfs-amd64 -r

7- create lxc container using ubuntu template
root@lxc-docker:/# lxc-create -n ubuntu14.04 -t ubuntu
Checking cache download in /var/cache/lxc/trusty/rootfs-amd64 ...
Copy /var/cache/lxc/trusty/rootfs-amd64 to /var/lib/lxc/ubuntu14.04/rootfs ...
Copying rootfs to /var/lib/lxc/ubuntu14.04/rootfs ...
Generating locales...
  en_US.UTF-8... done
Generation complete.

Current default time zone: 'America/New_York'
Local time is now:      Sun Dec 28 13:26:20 EST 2014.
Universal Time is now:  Sun Dec 28 18:26:20 UTC 2014.


##
# The default user is 'ubuntu' with password 'ubuntu'!
# Use the 'sudo' command to run tasks as root in the container.
##


-- now we create create lxc from from docker image


No comments:

Post a Comment