The first step is to make sure that ImageFactory is installed on your computer. To install it,
$ sudo dnf install imagefactory
If you already have it installed, you can obviously skip this step.
To create a base image, you will need to input two arguments:
- Kickstart file
- Template
The Kickstart file is used to tell ImageFactory what to install and how to install it. Below is the official Kickstart file for creating a (minimal) Fedora docker base image: https://git.fedorahosted.org/cgit/spin-kickstarts.git/tree/fedora-docker-base.ks
The template is used to tell ImageFactory which OS you want to install (version, architecture, etc.) and where to install it from. It essentially describes what to build. An example template can be seen below:
fedora-24-template.tdl
<template>
<name>fedora24-alpha</name>
<os>
<name>Fedora</name>
<version>24</version>
<arch>x86_64</arch>
<install type='url'>
<url>http://download.eng.bos.redhat.com/released/F-23/GOLD/Server/x86_64/os/</url>
</install>
<rootpw>rrrrr</rootpw>
</os>
</template>
*Note: Template files can have a .tdl or .xml format.
You will need to modify your Oz config file in order to create a Fedora 24 image. This config file is located at /etc/oz/oz.cfg
.
Uncomment #memory 1024
and change it to memory 2048
.
oz.cfg
[paths]
output_dir = /var/lib/libvirt/images
data_dir = /var/lib/oz
screenshot_dir = /var/lib/oz/screenshots
# sshprivkey = /etc/oz/id_rsa-icicle-gen
[libvirt]
uri = qemu:///system
image_type = raw
# type = kvm
# bridge_name = virbr0
# cpus = 1
memory = 2048
[cache]
original_media = yes
modified_media = no
jeos = no
[icicle]
safe_generation = no
Once you have gathered your input arguments and are ready to create a docker base image, you will need to run the following command as root:
# imagefactory --debug base_image --file-parameter install_script <kickstart> <template> --parameter offline_icicle true
Be sure to replace <kickstart>
with your kickstart file and replace <template>
with your template file.
This process will take about 5-10 minutes to run, and once it is finished, it will print out the ID of the image you just created. The final output will look something like this:
============ Final Image Details ============
UUID: 17206f41-5bd8-4578-84b9-a3fffc1cd168
Type: base_image
Image filename: /var/lib/imagefactory/storage/17206f41-5bd8-4578-84b9-a3fffc1cd168.body
Image build completed SUCCESSFULLY!
Next, we need to "docker compress" our image in order to prepare it for loading into docker:
# imagefactory --debug target_image --id <image id> docker --parameter compress xz
This time, replace <image id>
with the ID that imagefactory just printed out. (This is the UUID.)
Once this process completes, you have your Docker base image!
To load your docker-compressed image into Docker:
$ docker load -i /path/to/target-image-file
where the image file has the following format: <target image id>.body
(e.g., 5e380b80-d2e8-4506-a110-5c230eb34fda.body
)
This process creates a Docker image from your base image.
Note that both ImageFactory commands output different UUIDs. You want to use the docker-compressed UUID, not the base_image UUID.
I'd like to point out some mistakes that I made in trying to convert my Docker base image to a Docker image. Hopefully they'll help you if you run into any issues
Base images produced by ImageFactory are not Docker base images. Therefore, importing an ImageFactory base image into Docker will not work. In order to create a Docker base image, you must complete the Docker compression step listed at the end of step 4.
If you're creating a base image with ImageFactory, pay attention to the <name>
tag in your template file. If you create several base images with the same name and you don't tag them differently, Docker will simply overwrite your images.
To check the names of the Docker images you have created,
$ docker images
*This will print out all of your current Docker images, including their names, tags, image IDs, creation date, and virtual size.