签到成功

知道了

CNDBA社区CNDBA社区

Docker定制镜像

2021-10-01 23:07 1178 0 转载 Docker
作者: hbhe0316

Howto create a Docker Image for RHEL
RHEL docker images are not available from Docker Hub. It’s available from Redhat docker registry and the catalog can be accessedhere. However there could be cases where you might want to create a RHEL docker image from scratch. The following steps will guide you to create a RHEL docker image from scratch. While these steps are for creating RHEL 7.1 LE docker image on PowerPC servers, the same can be applied for creating RHEL docker image on Intel servers as well.
The steps below have been performed on an Ubuntu 15.10 OS running as a PowerKVM guest. However you can run the same steps on RHEL or Fedora as well.
Pre-requisites
Access to RHEL package repository. You can use a local repository created from RHEL installation ISO as described below

# mkdir -p /mnt/rhel7-repo
# mount -o loop RHEL-LE-7.1-20150219.1-Server-ppc64le-dvd1.iso /mnt/rhel7-repo/

Install ‘yum’ package. This is not required on a RHEL or Fedora system as it’ll be there by default.http://www.cndba.cn/hbhe0316/article/4822

# apt-get install yum

Steps to create a RHEL docker image
Create a new RPM root directory

# mkdir /rhel7-root
# export rpm_root=/rhel7-root

Initialize the new RPM root directory
# rpm --root ${rpm_root} --initdb
The rest of the install instructions will use this new RPM root as the install destination for a minimalistic RHEL OS.
Install the redhat-release-server rpm package for RHEL 7.1 LE

# rpm --root ${rpm_root} -ivh /mnt/rhel7-repo/Packages/redhat-release-server-7.1-1.ael7b.ppc64le.rpm

Configure yum repositories as required.
For example if you want to use only the local repository, then do the followinghttp://www.cndba.cn/hbhe0316/article/4822

# rm -f ${rpm_root}/etc/yum.repos.d/*.repo
# cat >${rpm_root}/etc/yum.repos.d/rhel71le.repo<<EOF
[rhel71le]
baseurl=file:///mnt/rhel7-repo/Server
enabled=1
EOF
cat >${rpm_root}/etc/yum.repos.d/rhel71le.repo<<EOF
[rhel-debuginfo]
name=Red Hat Enterprise Linux $releasever - $basearch - Debug
baseurl=file:///mnt/rhel7-repo/Server
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
EOF

rpmdb: /var/lib/rpm/Name: unexpected file type or format
Indeed, it’s a corrupt rpm database. Steps to resolve:http://www.cndba.cn/hbhe0316/article/4822http://www.cndba.cn/hbhe0316/article/4822

  1. Check for processes holding the rpm database open (usually in MUTEX/FUTEX states):
lsof | grep /var/lib/rpm

If it finds any, kill -9 them all.

  1. Delete any temporary DB files:
rm -fv /var/lib/rpm/__*
  1. Rebuild your RPM database:
rpm --rebuilddb -v -v

If you still have problems, a reboot is probably quickest, then repeat steps 2 and 3 above.

http://www.cndba.cn/hbhe0316/article/4822
http://www.cndba.cn/hbhe0316/article/4822

yum install setuptool tar vi unzip

If you encounter ‘No such file or directory’ error, then you’ll need to create the /etc/yum.repos.d directory.
Import GPG keys

 rpm --root ${rpm_root} --import  /mnt/rhel7-repo/RPM-GPG-KEY-redhat-*

Install minimalistic RHEL OShttp://www.cndba.cn/hbhe0316/article/4822

# yum -y --installroot=${rpm_root} install yum

This will install a minimalistic RHEL OS under /rhel7-root
Additional Customization
Chroot to the new RHEL installation and perform any additional customizations if required

# chroot ${rpm_root} /bin/bash
bash-4.2# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 7.1 (Maipo)

Convert this RHEL installation to a docker image

http://www.cndba.cn/hbhe0316/article/4822
http://www.cndba.cn/hbhe0316/article/4822

# tar -C ${rpm_root}/ -c . | docker import - rhel7le
9a6dac402e2bf561f833f644337f3061c6ff70ec906472d5c008755ca9ed7f1d
# docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
rhel7le               latest              9a6dac402e2b        11 seconds ago      360.6 MB

Use the new RHEL docker image

# docker run --hostname='rhel7-container' rhel7le uname -a
Linux rhel7-container 4.2.0-10-generic #12-Ubuntu SMP Tue Sep 15 19:46:04 UTC 2015 ppc64le ppc64le ppc64le GNU/Linux

Once you have created the RHEL docker image, you can push it to your local registry for sharing. Hope this will be of some help to you in your docker journey.http://www.cndba.cn/hbhe0316/article/4822

oracle,linux

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
hbhe0316

hbhe0316

关注

1.只有承认无知,才能装下新的东西; 2.进步来自一点点滴滴的积累; 3.广博让你更优秀,而专业让你无法替代; 4.挫折和失败能够转换为一种财富。

  • 889
    原创
  • 1
    翻译
  • 13
    转载
  • 24
    评论
  • 访问:1142745次
  • 积分:1523
  • 等级:核心会员
  • 排名:第6名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ