본문 바로가기
IT/Docker

Docker base image (도커 기본이미지)

by halizy 2018. 7. 15.

지난 포스팅에서 기본적인 도커 사용법에 대해 다뤄보았습니다. 

이번 포스팅은 기본 이미지를 만드는 방법에 대해 다뤄 볼 생각입니다.

문의 사항은 댓글로 남겨주시면 성심 성의껏 답변드리도록 하겠습니다






Docker Base Image


대부분의 Dockerfile은 부모이미지에서 시작합니다. 때문에 이미지 제어에 있어 제약이 있는 부분있습니다.

따라서 이미지 내용을 완전히 제어해야 할 때는 기본이미지를 만들어 사용해야 합니다.



Ubuntu


Centos

Busybox


Alpine





Size and layer




Nginx 설치



Ubuntu


$ cat ubuntu/Dockerfile


    FROM ubuntu:latest

    RUN \

      apt-get update && \

      apt-get install -y nginx &&

      echo "hello world ! - ubuntu base" > /usr/share/nginx/html/index.html

    EXPOSE 80 443

    CMD ["nginx", "-g", "daemon off;"]


$ docker build --tag nginx:ubuntu ubuntu/


$ docker run -itd --name nginx-ubuntu -p 80:80 nginx:ubuntu


$ curl localhost


    hello world ! - ubuntu base


$ docker images


REPOSITORY        TAG            IMAGE ID          CREATED       SIZE
nginx          ubuntu        316c56425afd       3 minutes ago     227.8MB


$ docker stop nginx-ubuntu




Centos


$ cat centos/Dockerfile


    FROM centos:latest

    RUN \

      yum update -y && \

      yum install -y epel-release && \

      yum install -y nginx && \

      echo "hello world ! - centos base" > /usr/share/nginx/html/index.html

    EXPOSE 80 443

    CMD ["nginx", "-g", "daemon off;"]


$ docker build --tag nginx:centos centos/


$ docker run -itd --name nginx-centos -p 80:80 nginx:centos


$ curl localhost


    hello world ! - centos base


$ docker images   


REPOSITORY TAG IMAGE ID CREATED            SIZE
nginx      centos      d8e852a89cea    4 minutes ago    345.1 MB


$ docker stop nginx-centos





Busybox



# opkg 사용을 위해 몇개의 파일이 추가


$ tree busybox


    busybox/

    ├── Dockerfile

    ├── functions.sh

    ├── index.html

    ├── nginx.conf

    ├── opkg.conf

    ├── opkg-install

    └── rootfs.tar

 

 

$ cat busybox/Dockerfile

 

    FROM busybox:latest

    ADD ./rootfs.tar /

    ADD ./opkg.conf         /etc/opkg.conf

    ADD ./opkg-install      /usr/bin/opkg-install

    ADD ./functions.sh      /lib/functions.sh

    RUN \

      opkg-cl install http://downloads.openwrt.org/snapshots/trunk/x86/64/packages/base/libgcc_5.3.0-1_x86_64.ipk && \

      opkg-cl install http://downloads.openwrt.org/snapshots/trunk/x86/64/packages/base/libc_1.1.14-1_x86_64.ipk && \

      /usr/bin/opkg-install nginx && \

      mkdir /var/lib/nginx

    ADD nginx.conf /etc/nginx/nginx.conf

    ADD index.html /usr/html/

    EXPOSE 80 443

    CMD ["/usr/sbin/nginx"]


$ docker build --tag nginx:busybox busybox/


$ docker run -itd --name nginx-busybox -p 80:80 nginx:busybox


$ curl localhost


    hello world ! - busybox base


$ docker images


REPOSITORY     TAG          IMAGE ID         CREATED        SIZE
nginx       busybox     32a69c9f7790      4 minutes ago      9.119 MB


$ docker stop nginx-busybox





Alpine



$ cat alpine/Dockerfile


    FROM alpine:latest

    RUN \

      apk add --update nginx && \

      echo "hello world ! - alpine base" > /usr/share/nginx/html/index.html

    EXPOSE 80 443

    CMD ["nginx", "-g", "daemon off;"]


$ docker build --tag nginx:alpine alpine/


$ docker run -itd --name nginx-alpine -p 80:80 nginx:alpine


$ curl localhost 


    hello world ! - alpine base


$ docker images


REPOSITORY TAG    IMAGE ID    CREATED    SIZE
nginx    alpine 64cc41bebfd6 2 minutes ago 

7.001 MB


$ docker stop nginx-alpine




 Nginx 이미지크기 


Ubuntu

Centos

Busybox

Alpine

227.8 MB

345.1 MB

9.119 MB

7.001 MB







댓글