Giter Club home page Giter Club logo

export-docker's Introduction

export-docker

Export a Docker container to a lxc container

How to use

sudo ./export-container.py <container id> <new container name>

Example:

$ sudo ./export-container.py f4e7e632964a registry
Exporting Docker container to a lxc container
Docker container id:  f4e7e632964a
New container name:  registry
Full container id  f4e7e632964a822bbd0e633b8ef8422c341d0b43d3e72a869c1154e461cf2302
Container exists [/var/lib/docker/containers/f4e7e632964a822bbd0e633b8ef8422c341d0b43d3e72a869c1154e461cf2302]? True
Rootfs exists [/var/lib/docker/devicemapper/mnt/f4e7e632964a822bbd0e633b8ef8422c341d0b43d3e72a869c1154e461cf2302/rootfs]? True
Init-rootfs exists [/var/lib/docker/devicemapper/mnt/f4e7e632964a822bbd0e633b8ef8422c341d0b43d3e72a869c1154e461cf2302-init/rootfs]? True
Copying rootfs...
Copying config files...
Creating run script...

It's all done! Now just type:
cd registry && sudo ./run.sh

Check the folder just created:

$ find registry/ -maxdepth 2
registry/
registry/rootfs
registry/rootfs/usr
registry/rootfs/home
...
registry/rootfs/tmp
registry/rootfs/root
registry/config.lxc.template
registry/run.sh
  • config.lxc.template: The lxc config file
  • run.sh: Script to run the container
  • rootfs/: Folder with all container files

To run:

$ sudo ./run.sh
root@f4e7e632964a:/#

Why

  • To have a lxc container independent from Docker (docker0 network interface is the only dependency)
  • To learn about lxc and Docker
  • For fun :)

export-docker's People

Contributors

fabiofalci avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

export-docker's Issues

Doesn't use API; needs root; doesn't work with current version of docker

The docker binary exposes all the functions needed to do this without root access and without direct access to the docker paths. The current approach doesn't seem to be portable. Why can't the docker export command be used?

sudo ./export-container.py 9d8291fb57d4 test
Exporting Docker container to a lxc container
('Docker container id: ', '9d8291fb57d4')
('New container name: ', 'test')
('Full container id ', '9d8291fb57d474082ad4e91ab6625e5e9b8f2da673ede41bfad8647e13bf447b')
Container exists [/var/lib/docker/containers/9d8291fb57d474082ad4e91ab6625e5e9b8f2da673ede41bfad8647e13bf447b]? True
Traceback (most recent call last):
  File "./export-container.py", line 208, in <module>
    main()
  File "./export-container.py", line 199, in main
    container.is_valid_container()
  File "./export-container.py", line 50, in is_valid_container
    self.lxc_rootfs_exists()
  File "./export-container.py", line 64, in lxc_rootfs_exists
    lines = tuple(open(self.config, "r"))
IOError: [Errno 2] No such file or directory: '/var/lib/docker/containers/9d8291fb57d474082ad4e91ab6625e5e9b8f2da673ede41bfad8647e13bf447b/config.lxc'


config.lxc not present in the container directory

Hi

Thanks for this project, looks really interesting

I give it a try but it's complaining that config.lxc is not present in the container directory
Is it a file docker is supposed to create on it's own ?

I'm running Docker version 1.6.2, build 7c8fca2

Any idea will be appreciated
Thanks
Damien

sudo ./export-container.py 5d07d443d8d7 fluentdlxc01
Exporting Docker container to a lxc container
('Docker container id: ', '5d07d443d8d7')
('New container name: ', 'fluentdlxc01')
('Full container id ', '5d07d443d8d7ad6a5524d5bbcc4146ab3ed54ba52d9126d7e8105f49c99012ca')
Container exists [/var/lib/docker/containers/5d07d443d8d7ad6a5524d5bbcc4146ab3ed54ba52d9126d7e8105f49c99012ca]? True
Traceback (most recent call last):
  File "./export-container.py", line 208, in <module>
    main()
  File "./export-container.py", line 199, in main
    container.is_valid_container()
  File "./export-container.py", line 50, in is_valid_container
    self.lxc_rootfs_exists()
  File "./export-container.py", line 64, in lxc_rootfs_exists
    lines = tuple(open(self.config, "r"))
IOError: [Errno 2] No such file or directory: '/var/lib/docker/containers/5d07d443d8d7ad6a5524d5bbcc4146ab3ed54ba52d9126d7e8105f49c99012ca/config.lxc'

Container dir

sudo ls -l /var/lib/docker/containers/5d07d443d8d7ad6a5524d5bbcc4146ab3ed54ba52d9126d7e8105f49c99012ca
total 28
-rw------- 1 root root  785 Dec  4 08:46 5d07d443d8d7ad6a5524d5bbcc4146ab3ed54ba52d9126d7e8105f49c99012ca-json.log
-rw-r--r-- 1 root root 2132 Dec  4 08:46 config.json
-rw-r--r-- 1 root root  639 Dec  4 08:46 hostconfig.json
-rw-r--r-- 1 root root   13 Dec  4 08:44 hostname
-rw-r--r-- 1 root root  175 Dec  4 08:44 hosts
-rw-r--r-- 1 root root  249 Dec  4 08:44 resolv.conf
-rw-r--r-- 1 root root   71 Dec  4 08:44 resolv.conf.hash

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.