언어 및 프레임워크 가이드
Dockerfile 만드는 법 가이드
2 분
도커는 애플리케이션을 컨테이너에 패키징하고 실행할 수 있게 해주는 기술입니다 back4app 컨테이너는 도커 기술을 기반으로 하며, 도커 컨테이너를 사용하여 애플리케이션을 격리하고 실행합니다 이는 성능 향상, 보안 강화, 배포 및 확장의 단순화와 같은 여러 가지 이점을 제공합니다 도커파일은 도커 이미지를 빌드하기 위한 지침을 포함하는 스크립트입니다 애플리케이션에 대한 도커파일을 만들기 위해서는 다음의 기본 단계를 따라야 합니다 기본 이미지 선택 (from) 첫 번째 단계는 도커파일에 대한 기본 이미지를 선택하는 것입니다 기본 이미지는 운영 체제와 애플리케이션에 필요한 런타임 종속성을 포함해야 합니다 도커 허브의 공식 이미지를 사용할 수 있으며, 신뢰할 수 있는 출처의 이미지를 선택할 수도 있습니다 작업 디렉토리 설정 (workdir) 다음으로, 애플리케이션 파일이 위치할 컨테이너 내의 작업 디렉토리를 설정해야 합니다 workdir 지침을 사용하여 작업 디렉토리를 설정할 수 있습니다 애플리케이션 파일 복사 (copy) 이제 애플리케이션 파일을 작업 디렉토리로 복사해야 합니다 copy 지침을 사용하여 파일을 복사할 수 있습니다 종속성 설치 (run) 애플리케이션에 종속성이 있는 경우, 이를 컨테이너에 설치해야 합니다 적절한 패키지 관리자를 사용하여 종속성을 설치할 수 있습니다 (예 apt get , yum , pip , 등) 진입점 정의 (cmd) 마지막 단계는 컨테이너의 진입점을 정의하는 것입니다 이는 컨테이너가 시작될 때 실행될 명령입니다 진입점은 애플리케이션을 시작해야 합니다 다음은 일반 애플리케이션을 위한 도커파일의 간단한 예입니다 nodejs bashcopy code \# use the official node js image as the base image from node 18 \# set the working directory in the container workdir /app \# copy the application files into the working directory copy /app \# install the application dependencies run npm install \# define the entry point for the container cmd \["npm", "start"] flask # use the official python image as the base image from python 3 8 \# set the working directory in the container workdir /app \# copy the application files into the working directory copy /app \# install the application dependencies run pip install r requirements txt \# define the entry point for the container cmd \["flask", "run", " host=0 0 0 0"] reactjs # use the official node js image as the base image from node 18 \# set the working directory in the container workdir /app \# copy the application files into the working directory copy /app \# install the application dependencies run npm install \# build the react application run npm run build \# expose port 3000 expose 3000 \# define the entry point for the container cmd \["npm", "start"] django # use the official python image as the base image from python 3 8 \# set the working directory in the container workdir /app \# copy the application files into the working directory copy /app \# install the application dependencies run pip install r requirements txt \# define the entry point for the container cmd \["python", "manage py", "runserver", "0 0 0 0 8000"] php # use the official php image as the base image from php 7 4 apache \# copy the application files into the container copy /var/www/html \# set the working directory in the container workdir /var/www/html \# install necessary php extensions run apt get update && apt get install y \\ libicu dev \\ libzip dev \\ && docker php ext install \\ intl \\ zip \\ && a2enmod rewrite \# expose port 80 expose 80 \# define the entry point for the container cmd \["apache2 foreground"] elixir # use the official elixir image as the base image from elixir 1 12 \# set the working directory in the container workdir /app \# copy the application files into the working directory copy /app \# install the application dependencies run mix local hex force && \\ mix local rebar force && \\ mix deps get \# build the application run mix compile \# define the entry point for the container cmd \["mix", "phx server"] laravel # use the official php image as the base image from php 7 4 apache \# copy the application files into the container copy /var/www/html \# set the working directory in the container workdir /var/www/html \# install necessary php extensions run apt get update && apt get install y \\ libicu dev \\ libzip dev \\ && docker php ext install \\ intl \\ zip \\ && a2enmod rewrite \# install composer run curl ss https //getcomposer org/installer | php install dir=/usr/local/bin filename=composer \# install laravel dependencies run composer install no dev \# expose port 80 expose 80 \# define the entry point for the container cmd \["apache2 foreground"] go # use the official go image as the base image from golang 1 15 \# set the working directory in the container workdir /app \# copy the application files into the working directory copy /app \# build the application run go build o main \# expose port 8080 expose 8080 \# define the entry point for the container cmd \[" /main"] rust # use the official rust image as the base image from rust 1 48 \# set the working directory in the container workdir /app \# copy the application files into the working directory copy /app \# build the application run cargo build release \# expose port 8080 expose 8080 \# define the entry point for the container cmd \[" /target/release/app"] dockerfile을 생성한 후, 이를 프로젝트 루트 또는 원하는 폴더에 붙여넣어야 합니다(단, app settings의 root 매개변수에서 이를 지정해야 합니다) 그리고 애플리케이션을 생성하거나 재배포해야 합니다 back4app은 이 파일을 기반으로 docker 이미지를 생성하고 이 이미지를 사용하여 컨테이너를 생성합니다 이렇게 하면 back4app 컨테이너에서 애플리케이션을 실행할 수 있습니다