É possível criar um contêiner do Docker usando este script :
[user@host]$ sudo sh mkimage-yum.sh -y /etc/yum.repos.d/epel.repo hello_container
resulta em:
+ version=7.1.1503
+ break
+ '[' -z 7.1.1503 ']'
+ tar --numeric-owner -c -C /tmp/mkimage-yum.sh.Kv8t1O .
+ docker import - hello_container:7.1.1503
c14b1e83cab7a34e5350ff527142e2c1e3e8c7cc5e2bc00419267c5a4ca53d1a
+ docker run -i -t hello_container:7.1.1503 echo success
success
+ rm -rf /tmp/mkimage-yum.sh.Kv8t1O
Problema
O script cria um contêiner Docker da versão mais recente do CentOS7. Eu gostaria de ter controle e criar um contêiner específico, por exemplo 6.3 em vez do último.
Tentativa
Eu modifiquei o script:
#!/usr/bin/env bash
yum_config=epel.repo
name="hello_container"
target=$(mktemp -d --tmpdir $(echo $name).XXXXXX)
set -x
mkdir -m 755 "$target"/dev
mknod -m 600 "$target"/dev/console c 5 1
mknod -m 600 "$target"/dev/initctl p
mknod -m 666 "$target"/dev/full c 1 7
mknod -m 666 "$target"/dev/null c 1 3
mknod -m 666 "$target"/dev/ptmx c 5 2
mknod -m 666 "$target"/dev/random c 1 8
mknod -m 666 "$target"/dev/tty c 5 0
mknod -m 666 "$target"/dev/tty0 c 4 0
mknod -m 666 "$target"/dev/urandom c 1 9
mknod -m 666 "$target"/dev/zero c 1 5
yum -c "$yum_config" --installroot="$target" --releasever=6 --setopt=tsflags=nodocs \
--setopt=group_package_types=mandatory -y groupinstall Core
yum -c "$yum_config" --installroot="$target" -y clean all
cat > "$target"/etc/sysconfig/network <<EOF
NETWORKING=yes
HOSTNAME=localhost.localdomain
EOF
rm -rf "$target"/usr/{{lib,share}/locale,{lib,lib64}/gconv,bin/localedef,sbin/build-locale-archive}
rm -rf "$target"/usr/share/{man,doc,info,gnome/help}
rm -rf "$target"/usr/share/cracklib
rm -rf "$target"/usr/share/i18n
rm -rf "$target"/var/cache/yum
mkdir -p --mode=0755 "$target"/var/cache/yum
rm -rf "$target"/sbin/sln
rm -rf "$target"/etc/ld.so.cache "$target"/var/cache/ldconfig
mkdir -p --mode=0755 "$target"/var/cache/ldconfig
version=6
tar --numeric-owner -c -C "$target" . | docker import - $name:$version
docker run -i -t $name:$version echo success
rm -rf "$target"
a emissão de sudo sh custom-mkimage-yum.sh
resulta em:
+ docker import - hello_container:6
d1a4989b92f5980d4f36e1365a72cc34569d61695841c478f488fd28dc8ad7e1
+ docker run -i -t hello_container:6 echo success
exec: "echo": executable file not found in $PATH
Error response from daemon: Cannot start container ef95a4dd4d895e611c1222c9cfe01b347fb30f56e3ab53c75b405ff193cec3b3: [8] System error: exec: "echo": executable file not found in $PATH
+ rm -rf /tmp/.RkMaJU