IT. POST LIST

POST ALL LABEL

DOCKER 이미지 제작 공방2 - febootstrap & debootstrap

By 때찌때찌맴매 - 4월 10, 2018


DOCKER 이미지 제작 공방

* 여러가지의 이미지 제작 방법을 포스팅 합니다. 이미지 제작 후 https://hub.docker.com/ 으로 업로드 방법은 추후에 포스팅 진행합니다.
* centos6 에서는 저장소에 febootstrap 관련 패키지들이 있으나 centos7 에서는 없기 때문에 패키지를 따로 설치 해야 합니다. 방법은 동일하고, 작업 진행은 centos6 이나 centos7  편한곳에서 진행합니다.
* ubuntu debootstrap 으로 제작이 가능합니다. (debootstrap 관련 포스팅 추가)
 

** docker 베이스 이미지 제작 - febootstrap & debootstrap


[ febootstrap 설치 -  centos 6 ]

[root@centos6 ]# yum install febootstrap fake* -y
.
.
.
[root@centos6 ]# rpm -qa | grep -P "febootstrap|fake"
fakeroot-1.12.2-22.2.el6.x86_64
fakechroot-libs-2.9-24.5.el6_1.1.x86_64
febootstrap-supermin-helper-3.21-4.el6.x86_64
fakechroot-2.9-24.5.el6_1.1.x86_64
febootstrap-3.21-4.el6.x86_64
fakeroot-libs-1.12.2-22.2.el6.x86_64

[ febootstrap 설치 -  centos 7 ]

[root@centos7 ]# yum install febootstrap fake* -y
.
.
.
[root@centos7 ]# rpm -qa | grep -P "febootstrap|fake"
fakeroot-1.18.4-2.el7.x86_64
fakeroot-libs-1.18.4-2.el7.x86_64

[root@centos7 ]# cd /usr/local/src
[root@centos7 ]# wget https://rpmfind.net/linux/centos/6.9/os/x86_64/Packages/febootstrap-3.21-4.el6.x86_64.rpm
[root@centos7 ]# wget https://rpmfind.net/linux/centos/6.9/os/x86_64/Packages/febootstrap-supermin-helper-3.21-4.el6.x86_64.rpm
[root@centos7 ]# wget https://rpmfind.net/linux/centos/6.9/os/x86_64/Packages/fakechroot-2.9-24.5.el6_1.1.x86_64.rpm
[root@centos7 ]# wget https://rpmfind.net/linux/centos/6.9/os/x86_64/Packages/fakechroot-libs-2.9-24.5.el6_1.1.x86_64.rpm
[root@centos7 ]# ll
합계 604
drwxr-xr-x.  2 root root   4096  4월 10 14:08 .
drwxr-xr-x. 13 root root   4096  3월 27 11:15 ..
-rw-r--r--   1 root root  23576  9월 26  2011 fakechroot-2.9-24.5.el6_1.1.x86_64.rpm
-rw-r--r--   1 root root  23240  9월 26  2011 fakechroot-libs-2.9-24.5.el6_1.1.x86_64.rpm
-rw-r--r--   1 root root 209020 11월 25  2013 febootstrap-3.21-4.el6.x86_64.rpm
-rw-r--r--   1 root root 345436 11월 25  2013 febootstrap-supermin-helper-3.21-4.el6.x86_64.rpm

[root@centos7 ]# rpm -Uvh ./*
경고: ./fakechroot-2.9-24.5.el6_1.1.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
준비 중...                         ################################# [100%]
Updating / installing...
   1:febootstrap-supermin-helper-3.21-################################# [ 25%]
   2:fakechroot-libs-2.9-24.5.el6_1.1 ################################# [ 50%]
   3:fakechroot-2.9-24.5.el6_1.1      ################################# [ 75%]
   4:febootstrap-3.21-4.el6           ################################# [100%]

[root@centos7 ]# rpm -qa | grep -P "febootstrap|fake"
fakeroot-1.18.4-2.el7.x86_64
febootstrap-3.21-4.el6.x86_64
fakeroot-libs-1.18.4-2.el7.x86_64
febootstrap-supermin-helper-3.21-4.el6.x86_64
fakechroot-2.9-24.5.el6_1.1.x86_64
fakechroot-libs-2.9-24.5.el6_1.1.x86_64

*centos7 저장소에는 해당 패키지가 없기 때문에 centos6 패키지를 가져가 사용했습니다. 호환성에 문제가 없으니 잘되는군요.


[ febootstrap 이미지 생성 및 도킹 ]

febootstrap [--options] REPO TARGET [MIRROR]

[root@centos7]# febootstrap -u http://mirror.kakao.com/centos/7.4.1708/updates/x86_64/ centos7.4 centos7 http://mirror.kakao.com/centos/7.4.1708/os/x86_64/

또는

[root@centos7]# febootstrap -i yum -i bash -i wget -i net-tools -i iputils -i iproute -i openssh-server -i openssh-clients centos7.4 centos7 http://mirror.kakao.com/centos/7.4.1708/os/x86_64/

* 위 의 명령어로 진행하게 되면 updates 패키지들을 모두 다운 및 설치 진행 하고, 아래 명령어로 진행하게 되면 최소한의 패키지 설치로 이미지가 생성이됩니다. 해당 방식을 통해 원하는 패키지를 미리 설치 해서 이미지를 생성 준비를 합니다. 두 명령어들의 용량은 약 2배 정도 차이가 나게 됩니다.

[root@centos7]# ll
합계 0
drwxr-xr-x  7 root root  83  4월 10 15:08 .
drwxr-xr-x  4 root root  78  4월 10 10:38 ..
drwxr-xr-x  2 root root  30  4월 10 11:00 centos6
dr-xr-xr-x 17 root root 224  4월 10 15:08 centos7

[root@centos7]# tar -C centos7 -c . | docker import  - centos7.4

또는 
[root@centos7]# cd centos7
[root@centos7]# tar -c . | docker import  - centos7.4

[root@centos7]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos7.4           latest              79b78179cd69        53 seconds ago      490 MB
centos6-base        latest              4257dd712401        4 hours ago         2.3 GB

[root@centos7]# docker run -it --name centos7 centos7.4 /bin/bash
bash-4.2# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core) 

* 정상적으로 도킹이 완료 되었습니다.

* 우분투 debootstrap은 코드와 저장될 디렉토리 명만 지정하면 됩니다.
* 코드 정보는 https://wiki.ubuntu.com/DevelopmentCodeNames  에서 확인 바랍니다.
* 현 포스팅은 16.04버젼으로 xenial 로 진행합니다.


[ debootstrap 이미지 생성 및 도킹 ]

root@ubuntu:/home# apt-get install debootstrap -y
root@ubuntu:/home# debootstrap
I: usage: [OPTION]... <suite> <target> [<mirror> [<script>]]
debootstrap {code} {directory}

root@ubuntu:/home# debootstrap xenial xenial
I: Retrieving InRelease 
I: Checking Release signature
I: Valid Release signature (key id 790BC7277767219C42C86F933B4FE6ACC0B21F32)
I: Retrieving Packages 
I: Validating Packages 
I: Resolving dependencies of required packages...
I: Resolving dependencies of base packages...
I: Checking component main on http://archive.ubuntu.com/ubuntu...
I: Retrieving adduser 3.113+nmu3ubuntu4
.
.
.
I: Base system installed successfully.

root@ubuntu:/home# ll
total 233484
drwxr-xr-x  3 root root      4096 Apr 17 11:52 ./
drwxr-xr-x 23 root root      4096 Apr 13 15:21 ../
-rw-r--r--  1 root root 239073280 Apr 11 17:23 ubuntu16.04.tar
drwxr-xr-x 21 root root      4096 Apr 17 11:58 xenial/

root@ubuntu:/home# cd xenial/
root@ubuntu:/home/xenial# ll
total 84
drwxr-xr-x 21 root root 4096 Apr 17 11:58 ./
drwxr-xr-x  3 root root 4096 Apr 17 11:52 ../
drwxr-xr-x  2 root root 4096 Apr 17 11:57 bin/
drwxr-xr-x  2 root root 4096 Apr 13  2016 boot/
drwxr-xr-x  4 root root 4096 Apr 17 11:57 dev/
drwxr-xr-x 63 root root 4096 Apr 17 11:58 etc/
drwxr-xr-x  2 root root 4096 Apr 13  2016 home/
drwxr-xr-x 11 root root 4096 Apr 17 11:57 lib/
drwxr-xr-x  2 root root 4096 Apr 17 11:57 lib64/
drwxr-xr-x  2 root root 4096 Apr 17 11:57 media/
drwxr-xr-x  2 root root 4096 Apr 17 11:57 mnt/
drwxr-xr-x  2 root root 4096 Apr 17 11:57 opt/
drwxr-xr-x  2 root root 4096 Apr 13  2016 proc/
drwx------  2 root root 4096 Apr 17 11:57 root/
drwxr-xr-x  6 root root 4096 Apr 17 11:58 run/
drwxr-xr-x  2 root root 4096 Apr 17 11:58 sbin/
drwxr-xr-x  2 root root 4096 Apr 17 11:57 srv/
drwxr-xr-x  2 root root 4096 Feb  5  2016 sys/
drwxrwxrwt  2 root root 4096 Apr 17 11:58 tmp/
drwxr-xr-x 10 root root 4096 Apr 17 11:57 usr/
drwxr-xr-x 11 root root 4096 Apr 17 11:57 var/

* os관련 파일들이 정상적으로 다운 받아졌습니다. 도킹은 압축을 통해 사용하거나 rsync 등을 이용하여 docker 서비스로 넘겨 사용합니다.



[ 생성된 이미지 압축 및 도킹 ]

* 해당 작업은 ubuntu, centos 동일합니다.

=================================================================================================

[ ERROR ]

[root@centos7]# tar cvf centos7.tar centos7
[root@centos7]# ll
합계 491740
drwxr-xr-x  7 root root       102  4월 10 15:52 .
drwxr-xr-x  4 root root        78  4월 10 10:38 ..
drwxr-xr-x  2 root root        30  4월 10 11:00 centos6
dr-xr-xr-x 17 root root       224  4월 10 15:08 centos7
-rw-r--r--  1 root root 503541760  4월 10 15:52 centos7.tar

[root@centos7]# docker import centos7.tar centos7.4_2
sha256:10e65a71cadf3b64018d600042d67494619338507bcb7965791fc3db42d72981

[root@centos7]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos7.4_2         latest              10e65a71cadf        6 seconds ago       490 MB
centos7.4           latest              79b78179cd69        3 minutes ago       490 MB
centos6-base        latest              4257dd712401        4 hours ago         2.3 GB

[root@centos7]# docker run -it --name centos7_2 centos7.4_2 /bin/bash
/usr/bin/docker-current: Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "exec: \"/bin/bash\": stat /bin/bash: no such file or directory".

=================================================================================================

* 일반적인 압축을 통해 도킹하게 되면 이미지 도킹은 되지만, 보기와 같이 에러가 출력 됩니다.이미지 압축은 하되, chroot로 마운트 후 현재 os 이미지화 처럼 압축합니다.

[root@centos7]# chroot centos7
bash-4.2# tar --numeric-owner --exclude=/proc --exclude=/sys --exclude=/boot --exclude=/usr/lib/firmware --exclude=/usr/lib/modules --exclude=/usr/lib/udev -cvf centos7.tar /
bash-4.2# exit

* 압축은 위 처럼 최소한으로 작업을 해도 되고," tar -cvf centos7.tar / " 처럼 간략하게 해도 무방합니다.

[root@centos7]# mv centos7/centos7.tar ../
[root@centos7]# ll
합계 485420
drwxr-xr-x  7 root root       102  4월 10 16:06 .
drwxr-xr-x  4 root root        78  4월 10 16:08 ..
drwxr-xr-x  2 root root        30  4월 10 11:00 centos6
dr-xr-xr-x 17 root root       224  4월 10 16:06 centos7
-rw-r--r--  1 root root 497070080  4월 10 16:05 centos7.tar


[root@centos7]# docker import centos7.tar centos7.4_2
sha256:32eb5cc245e3c6d6227408543fc906a4676fb29f356819a7d8da19a22572d3fb

[root@centos7]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos7.4_2         latest              32eb5cc245e3        19 seconds ago      490 MB
centos7.4           latest              7f44ed3cf057        30 minutes ago      490 MB
centos6-base        latest              4257dd712401        4 hours ago         2.3 GB

[root@centos7]# docker run -it --name centos7_2 centos7.4_2 /bin/bash
bash-4.2# 

[root@centos7]# docker ps -a
CONTAINER ID      IMAGE         COMMAND       CREATED           STATUS         PORTS   NAMES
711e4f0cbb51      centos7.4_2   "/bin/bash"   9 minutes ago   Exited (0) 18 seconds ago centos7_2
9ce0f0ec7b2f      centos7.4     "/bin/bash"   40 minutes ago  Exited (137) 37 minu…     centos7
183dd65101ce      centos6-base  "/bin/bash"   5 hours ago     Exited (0) 5 hours ago    cent6

* 배포 방식은 hub.docker.com 에 업로드 후 다운 방식을 사용해도 되고, 도메인 형태로 " docker import https://hoguinside.com/centos7.tar centos7 " 사용 가능합니다.


  • Share:

You Might Also Like

0 개의 댓글