Docker 이미지 만들기 - dockerfile

Look! there's a flower!·2024년 4월 8일

도커 이미지 만들기

  1. pull 로 기존에 만들어진 이미지 가져오기
  2. 만들어진 이미지에서 컨테이너 변경해서 이미지 만들기
  3. dockerfile을 빌드 하기

git이 설치된 우분투 만들기

이미지 저장 디렉토리 만든 후 Dockerfile 작성, 그리고 build
$ mkdir git-from-dockerfile
$ cd git-from-dockerfile
$ cat > Dockerfile
From ubuntu:bionic
RUN apt-get update
RUN apt-get install -y git
$ docker build -t ubuntu:git-from-dockerfile .
Sending build context to Docker daemon 3.072kB
Step 1/3 : FROM ubuntu:bionic
---> 4e5021d210f6
Step 2/3 : RUN apt-get update
...
---> c2110a74f55e
Step 3/3 : RUN apt-get install -y -qq git
...
---> cc770735315e
Successfully built cc770735315e
Successfully tagged ubuntu:git-from-dockerfile
// 확인
$ docker run -it ubuntu:git-from-dockerfile bash
root@f98f0bd06b67:/# git --version
git version 2.17.1

위키(moniwiki) 웹어플리케이션서버 도커

  • 모니위키 : php, 아파치 기반 위키
    $ git clone https://github.com/nacyot/docker-moniwiki.git
    $ cd docker-moniwiki/moniwiki
  • 이 디렉토리에는 이미 Dockerfile 만들어져 있음
    $ cat > Dockerfile
    FROM ubuntu:14.04

RUN apt-get update &&\
apt-get -qq -y install git curl build-essential apache2 php5 libapache2-mod-php5 rcs

WORKDIR /tmp
RUN \
curl -L -O https://github.com/wkpark/moniwiki/archive/v1.2.5p1.tar.gz &&\
tar xf /tmp/v1.2.5p1.tar.gz &&\
mv moniwiki-1.2.5p1 /var/www/html/moniwiki &&\
chown -R www-data:www-data /var/www/html/moniwiki &&\
chmod 777 /var/www/html/moniwiki/data/ /var/www/html/moniwiki/ &&\
chmod +x /var/www/html/moniwiki/secure.sh &&\
/var/www/html/moniwiki/secure.sh

RUN a2enmod rewrite

ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2

EXPOSE 80

CMD bash -c "source /etc/apache2/envvars && /usr/sbin/apache2 -D FOREGROUND"

  • 빌드
    $ docker build -t nacyot/moniwiki:latest .
    Sending build context to Docker daemon 7.68kB
    Step 1/10 : FROM ubuntu:14.04
    ...
    Successfully built 408c35f3d162
    Successfully tagged nacyot/moniwiki:latest

  • 실행 확인
    $ docker run -d -p 9999:80 nacyot/moniwiki:latest
    746443ad118afdb3f254eedaeeada5abc2b125c7263bc5e67c2964b570166187

-d 는 daemon (반대로 -i는 interactive)
-p 는 포트포워딩

profile
Why don't you take a look around for a moment?

0개의 댓글