I think that what @dhalsher is attempting to do is indeed valid.
I was personally interested in doing the same thing and would have liked it if people addressed what I was inquiring about.
Below is one way I discovered to do what @dhalsher wanted to do which is to convert a Docker container to an LXC container template in Proxmox.
In the case of Docker images representing distributions and that have a shell entrypoint, this can be done in the following way:
1. Using Docker, pull the distribution image which you want to convert to an LXC (.tar.gz) template using the
docker pull
command
2. Run the docker image using
docker run -id <image>
3. Once the image is running, keep note of the container ID you see as the result of the previous command, call it
<container>
4. Export the root filesystem within the running container to a tarball using
docker export --output dockerexport.tar <container>
5. Compress the tarball using
gzip < dockerexport.tar > dockerexport.tar.gz
6. Rename the now-LXC-template and move it to the templates directory on the root Proxmox node Debian system (usually at
/var/lib/vz/template/cache
)
These steps can also be performed using the following one liner (using the bash Docker image as example):
Bash:
docker export $(docker run -id bash) | gzip > bash.tar.gz
To perform these steps, you will need a VM that has Docker installed and enough disk space for converting big images.
To move the resulting template (.tar.gz) file to the templates directory on the node's root Debian system: you can either mount the filesystem of the VM using
pct mount
and then copy the file while on the root Debian system, or use more conventional methods like
scp
(which can be called from the VM or the root system).
An example SCP invocation from the VM:
Bash:
scp bash.tar.gz root@<ip-address-of-node>:/var/lib/vz/template/cache
I followed this method to successfully convert the
universal devcontainer Docker image from Microsoft to an LXC container template, which worked nicely. Note that for a big image like this one (10GB), it makes more sense to run the steps separately rather than using a one liner.
After the conversion and transferring the resulting template, do not forget to:
1. Kill the Docker container using
docker kill <container>
2. Delete the docker image using
docker image remove <image>
3. Delete the
tar
and
tar.gz
files