can i create a LXC image from my own custom OS?

2/18/2018

Am new to lxc. I want to create my own lxc containers from existing OSs(my own unix kernel compiled in different architecture). I am trying to use "lxc-create". Can anyone suggest me how to create my own containers and is it possible to create one or not with this approach? Do I need to change any configurations after creating my own container?

If lxc is not suitable for this, can I achieve it with any other container-engines? P.S. I don't need vms or any hypervisors to achieve the same.

-- subrat
container-image
google-kubernetes-engine
lxc
lxc-docker
lxd

1 Answer

2/19/2018

Just to clarify, are you trying to create the image for the container from your own running operating system? If so, I don't believe this is possible using lxc-create.

lxc-create can be used to download publicly available images of various distributions. For example, you can run this command:

 lxc-create -t download -n my-container-name 

to download an image and create a container from that image. When you run this command, a download template will display a list of distributions available, from which you will be able to create a running conainter. For more information on this please see here.

The usual procedure to configure you own containers to your own specifications would be to build an image for your requirements from a base operating system image. There are a couple of ways you can do this. From the 'Manually building an image section' section here:

1) Generate a container filesystem. This entirely depends on the distribution you’re using. For Ubuntu and Debian, it would be by using debootstrap.

2) Configure anything that’s needed for the distribution to work properly in a container (if anything is needed).

3) Make a tarball of that container filesystem, optionally compress it.

4) Write a new metadata.yaml file based on the one described above.

5) Create another tarball containing that metadata.yaml file.

6) Import those two tarballs as a LXD image with:

lxc image import <metadata tarball> <rootfs tarball> --alias some-name

Another method would be to create a running container from a generic linux image (as described earlier using the lxc-create command), then enter the shell of the container so that you can change the configuration to you required needs, then publish the amended container as a new image. For example:

lxc launch ubuntu:14.04 my-container
lxc exec my-container bash
<do whatever change you want>
lxc publish my-container --alias my-new-image

Once you have configured your purpose made images, you can run containers from those images.

In relation to your question about other possibilities, I would suggest looking into Docker containers. If you are using Google Container Engine in some capacity (as the tags on this post suggest) you would then be able to utilise Container Registry to tag and store the different version of your images, and there is also a great deal of documentation and public images available for Docker online. If you would like to integrate it with VMs in GCP, there is some good information here if you would like to learn more.

-- neilH
Source: StackOverflow