Browse code

Added new mkimage-yum.sh script to create CentOS base images

mkimage-rinse.sh requires rinse, which is not readily available on
CentOS or Fedora. Plus, creating a base image is trivial with yum
alone.

Docker-DCO-1.1-Signed-off-by: Chris St. Pierre <chris.a.st.pierre@gmail.com> (github: stpierre)

Chris St. Pierre authored on 2014/01/17 22:46:11
Showing 3 changed files
... ...
@@ -1,4 +1,11 @@
1 1
 #!/usr/bin/env bash
2
+#
3
+# Create a base CentOS Docker image.
4
+
5
+# This script is useful on systems with rinse available (e.g.,
6
+# building a CentOS image on Debian).  See contrib/mkimage-yum.sh for
7
+# a way to build CentOS images on systems with yum installed.
8
+
2 9
 set -e
3 10
 
4 11
 repo="$1"
5 12
new file mode 100755
... ...
@@ -0,0 +1,90 @@
0
+#!/bin/bash
1
+#
2
+# Create a base CentOS Docker image.
3
+#
4
+# This script is useful on systems with yum installed (e.g., building
5
+# a CentOS image on CentOS).  See contrib/mkimage-rinse.sh for a way
6
+# to build CentOS images on other systems.
7
+
8
+usage() {
9
+    cat <<EOOPTS
10
+$(basename $0) [OPTIONS] <name>
11
+OPTIONS:
12
+  -y <yumconf>  The path to the yum config to install packages from. The
13
+                default is /etc/yum.conf.
14
+EOOPTS
15
+    exit 1
16
+}
17
+
18
+# option defaults
19
+yum_config=/etc/yum.conf
20
+while getopts ":y:h" opt; do
21
+    case $opt in
22
+        y)
23
+            yum_config=$OPTARG
24
+            ;;
25
+        h)
26
+            usage
27
+            ;;
28
+        \?)
29
+            echo "Invalid option: -$OPTARG"
30
+            usage
31
+            ;;
32
+    esac
33
+done
34
+shift $((OPTIND - 1))
35
+name=$1
36
+
37
+if [[ -z $name ]]; then
38
+    usage
39
+fi
40
+
41
+#--------------------
42
+
43
+target=$(mktemp -d --tmpdir $(basename $0).XXXXXX)
44
+
45
+set -x
46
+
47
+for dev in console null zero urandom; do
48
+    /sbin/MAKEDEV -d "$target"/dev -x $dev
49
+done
50
+
51
+yum -c "$yum_config" --installroot="$target" --setopt=tsflags=nodocs \
52
+    --setopt=group_package_types=mandatory -y groupinstall Core
53
+yum -c "$yum_config" --installroot="$mount" -y clean all
54
+
55
+cat > "$target"/etc/sysconfig/network <<EOF
56
+NETWORKING=yes
57
+HOSTNAME=localhost.localdomain
58
+EOF
59
+
60
+# effectively: febootstrap-minimize --keep-zoneinfo --keep-rpmdb
61
+# --keep-services "$target".  Stolen from mkimage-rinse.sh
62
+#  locales
63
+rm -rf "$target"/usr/{{lib,share}/locale,{lib,lib64}/gconv,bin/localedef,sbin/build-locale-archive}
64
+#  docs
65
+rm -rf "$target"/usr/share/{man,doc,info,gnome/help}
66
+#  cracklib
67
+rm -rf "$target"/usr/share/cracklib
68
+#  i18n
69
+rm -rf "$target"/usr/share/i18n
70
+#  sln
71
+rm -rf "$target"/sbin/sln
72
+#  ldconfig
73
+rm -rf "$target"/etc/ld.so.cache
74
+rm -rf "$target"/var/cache/ldconfig/*
75
+
76
+version=
77
+if [ -r "$target"/etc/redhat-release ]; then
78
+    version="$(sed 's/^[^0-9\]*\([0-9.]\+\).*$/\1/' /etc/redhat-release)"
79
+fi
80
+
81
+if [ -z "$version" ]; then
82
+    echo >&2 "warning: cannot autodetect OS version, using '$name' as tag"
83
+    version=$name
84
+fi
85
+
86
+tar --numeric-owner -c -C "$target" . | docker import - $name:$version
87
+docker run -i -t $name:$version echo success
88
+
89
+rm -rf "$target"
... ...
@@ -37,7 +37,10 @@ There are more example scripts for creating base images in the
37 37
 Docker Github Repo:
38 38
 
39 39
 * `BusyBox <https://github.com/dotcloud/docker/blob/master/contrib/mkimage-busybox.sh>`_
40
-* `CentOS / Scientific Linux CERN (SLC)
40
+* CentOS / Scientific Linux CERN (SLC) `on Debian/Ubuntu
41 41
   <https://github.com/dotcloud/docker/blob/master/contrib/mkimage-rinse.sh>`_
42
+  or
43
+  `on CentOS/RHEL/SLC/etc.
44
+  <https://github.com/dotcloud/docker/blob/master/contrib/mkimage-yum.sh>`_
42 45
 * `Debian / Ubuntu
43 46
   <https://github.com/dotcloud/docker/blob/master/contrib/mkimage-debootstrap.sh>`_