ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Node, Nginx를 설치하는 Dockerfile
    카테고리 없음 2023. 6. 1. 13:59

    Dockerfile에서 Amazone Linux를 기반으로 nginx를 설치 하는 방법은 일반적으로 아래와 같은 명령어를 이용합니다

    from amazonlinux
    
    RUN  yum update --security --bugfix -y
    
    RUN yum install -y python3 pip3
    RUN  yum -y install gcc-c++ make
    RUN  yum -y install curl
    
    # install nginx
    RUN amazon-linux-extras install -y nginx1
    RUN nginx -v

    nginx에서 필요한 추가 모듈을 설치하기 위해서 (ex: http_sub_module) 컴파일 설치를 해야 합니다.
    이때 사용하는 Dockerfile은 아래와 같습니다.

    from amazonlinux
    
    RUN  yum update --security --bugfix -y
    
    RUN yum install -y python3 pip3
    RUN  yum -y install gcc-c++ make
    RUN  yum -y install curl
    
    # install node
    RUN curl -sL https://rpm.nodesource.com/setup_16.x |  bash -
    RUN  yum install -y nodejs
    
    # datetime zone setting
    RUN date
    RUN mv /etc/localtime /etc/localtime_org
    RUN ln -s /usr/share/zoneinfo/Asia/Seoul /etc/localtime
    RUN date
    
    # filebeat for opensearch
    COPY ./filebeat-oss-7.10.2-x86_64.rpm .
    RUN yum install -y  filebeat-oss-7.10.2-x86_64.rpm
    
    # install nginx
    # RUN amazon-linux-extras install -y nginx1
    # RUN nginx -v
    
    RUN yum install -y wget tar gzip gcc g++ make gcc-c++ libxslt-devel perl curl
    
    # Nginx 설치 디렉토리 설정
    RUN mkdir nginx_source
    WORKDIR ./nginx_source/
    
    # nginx-1.20.2 다운
    RUN wget https://nginx.org/download/nginx-1.20.2.tar.gz
    RUN tar xvf nginx-1.20.2.tar.gz
    
    # Nginx 설치를 위한 모듈들 설치 START
    RUN wget  https://sourceforge.net/projects/pcre/files/pcre/8.45/pcre-8.45.tar.gz
    RUN tar xvf pcre-8.45.tar.gz
    
    RUN wget https://www.openssl.org/source/openssl-1.1.1l.tar.gz
    RUN tar -xzvf openssl-1.1.1l.tar.gz
    
    # RUN wget https://fossies.org/linux/misc/legacy/zlib-1.2.11.tar.gz
    RUN wget https://github.com/madler/zlib/archive/v1.2.11.tar.gz
    RUN tar zxf v1.2.11.tar.gz
    # Nginx 설치를 위한 모듈들 설치 END
    
    # 실행 계정 생성
    #RUN useradd --shell /sbin/nologin www-data
    
    RUN ls -al
    WORKDIR ./nginx-1.20.2/
    # 컴파일 옵션 설정 **--with-http_sub_module** 내가 추가한 옵션이다.
    RUN  ./configure \
      --with-http_sub_module \
      --with-zlib=../zlib-1.2.11 \
      --with-pcre=../pcre-8.45 \
      --with-openssl=../openssl-1.1.1l \
      --with-http_ssl_module \
      --with-debug  \
      --prefix=/etc/nginx
    #  --user=www-data \
    #  --group=www-data
    
    RUN  make;
    RUN  make install;
    
    RUN /etc/nginx/sbin/nginx -v

    위의 이미지에서 nginx 실행, 설정 파일의 위치는 아래와 같습니다.

    # 설정파일 위치
    /etc/nginx/conf/nginx.conf
    # 실행 파일 위치
    /etc/nginx/sbin/nginx 

    해당 이미지는 nginx가 foreground로 실행되고 있지 않기 때문에, 이미지 실행시 종료되지 않고 실행을 원한다면 Dockerfile에 아래 명령어로 추가 해야 합니다

    # 외부 오픈 port
    EXPOSE 80
    # foreground 실행 명령어
    CMD ["/etc/nginx/sbin/nginx", "-g", "daemon off;"]

    나중에 Docker 이미지 생성이 필요하면 참고 하려고 남겨 둡니다! :)

Designed by Tistory.