Detail Docker container base system image packaging

  • 2020-06-01 11:19:53
  • OfStack

Because the container itself is a Shared host operating system kernel, the container base system image package itself is a standard Linux rootfs + user-defined tool. With this in mind, we can build our own container base system image.

There are many ways to build standard Linux rootfs, and major distributions such as Redhat, Debian, and SUSE all provide tooling support.

The general process is as follows:

Building the basics of rootfs -- > Configure basic system parameters -- > Deploy user-defined software -- > Cleaning system -- > Packaged as a container image -- > Test image -- > Release the warehouse

Taking Ubuntu 16.04.01 LTS version as an example, make an Docker basic system image of Ubuntu 16.04.01 LTS:

1. Install Debootstrap:


sudo apt install debootstrap

2. Build rootfs of Ubuntu 16.04 LTS through Debootstrap:

1) create the rootfs storage location, such as we store the new rootfs in /opt/new_os:


 sudo mkdir -p /opt/new_os

2) build rootfs of Ubuntu 16.04 LTS (see help for Debootstrap tool parameters) :


sudo debootstrap --verbose --arch=amd64 xenial /opt/new_os http://mirrors.aliyun.com/ubuntu

3) basic system parameters:

a, switch to new rootfs:


sudo chroot /opt/new_os /bin/bash

b, installation base package (please install according to actual requirements) :


 apt -y update && apt -y upgrade && apt -y install vim locales

c, configure the system character set (follow the prompts) :


dpkg-reconfigure locales

d, configuration time zone:


cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

Optional: configure the version information of the 3rd party derivative system (e.g., UbuntuKylin)


    
            tee /etc/ubuntukylin-release <<- ' EOF'
            DISTRIB_ID=Ubuntu Kylin
            DISTRIB_RELEASE=16.04
            DISTRIB_CODENAME=xenial
            DISTRIB_DESCRIPTION="Ubuntu Kylin 16.04"
            EOF

f, cleaning system:


 rm -Rf /tmp/* && apt clean

g, exit the current rootfs


 exit

4) package and create the Docker image (prerequisite: the current system has configured the Docker runtime environment) :


 sudo mkdir -p /opt/new_os
0

5) testing


 sudo mkdir -p /opt/new_os
1

3. Publish to the warehouse (take the official warehouse as an example, private warehouse please upload by yourself)


 sudo mkdir -p /opt/new_os
2

4. Finish.

5. In addition, if you want to package the current system environment as a container basic image, mainly for the processing of rootfs, you can refer to the following command:


tar --numeric-owner --exclude=/proc --exclude=/sys -cvf new_os.tar /

 sudo mkdir -p /opt/new_os
4

or


 sudo mkdir -p /opt/new_os
5

Related articles: