RUN apt update && apt install -y nginxRUN [“/bin/bash”, “-c”, “apt update”]
RUN [“/bin/bash”, “-c”, “apt install -y nginx”]CMD [“python”, “app.py”]HEALTHCHECK --interval=1m --timeout=3s --retries=5 CMD curl -f http://localhost || exit 1docker build [옵션] 이미지이름[:태그] 경로 | URL | 압축파일
도커 파일이 없는 경우
우분투 위에 아파치 웹 서버 위에 PHP를 이용해서 웹 애플리케이션을 구현하는 경우, 우분투 이미지를 이용해서 컨테이너를 생성하고 컨테이너 안에 접속을 해서 아파치 웹 서버를 설치하고 아파치 웹 서버를 구동한 후 php를 설치하고 그 위에 코드를 작성해야 함
동일한 작업을 Dockerfile을 이용
Dockerfile에 모든 명령어를 작성해두고 한 번의 명령어로 수행
mkdir phpappcd phpapp도커 파일을 생성하고 작성(vi Dockerfile)
FROM ubuntu:14.04
MAINTAINER "bh <yachae1101@naver.com>"
LABEL title "IaC PHP application"
RUN apt-get update && apt-get install -y apache2 php5 git curl ssh wget
#Apache2 Environment Variable
ENV APACHE2_RUN_USER www-data
ENV APACHE2_RUN_GROUP www-data
ENV APACHE2_LOG_DIR /var/log/apache2
ENV APACHE2_WEB_DIR /var/www/html
ENV APACHE2_PID_FILE /var/run/apache2/apache2.pid
#basic web page
RUN echo 'Hello Docker Application' > /var/www/html/index.html
#PHP 파일
RUN echo '<?php phpinfo(); ?>' > /var/www/html/index.php
EXPOSE 80
WORKDIR /var/www/html
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
docker build -t myphpapp:1.0 .
docker images
docker run -dit -p 8101:80 --name phpapp1 myphpapp:1.0docker ps
curl localhost:8101
디렉토리를 생성하고 프롬프트 이동
mkdir python_lab
cd python_lab
nano Dockerfile 명령으로 파일을 생성하고 작성
FROM ubuntu:latest
RUN apt-get install python
이미지 빌드: 실패(apt-get update를 하지 않아서 실패)
docker build -t mypyapp:1.0 .

nano Dockerfile 명령으로 파일을 생성하고 수정
FROM ubuntu:latest
RUN apt-get update
RUN apt-get install python
이미지 빌드: 실패(대화식으로 작업하도록 해서 실패: 패키지를 설치할 때는 -y 옵션을 추가해서 자동으로 설치되도록 해주어야 합니다.)
docker build -t mypyapp:1.0 .

nano Dockerfile 명령으로 파일을 생성하고 수정
FROM ubuntu:latest
RUN apt-get update
RUN apt-get install python -y
이미지 빌드: 성공
docker build -t mypyapp:1.0 .
Dockerfile을 생성
FROM ubuntu:latest
RUN apt-get update && apt-get install -y nginx curl vim
RUN echo 'Docker Container Application.' > /var/www/html/index.html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
이미지 빌드 : 126.2초
docker build -f Dockerfile -t webapp:1.0 .

docker build -f Dockerfile -t webapp:2.0 .
FROM ubuntu:20.04
COPY app.py /app
RUN apt-get update && apt-get -y install python python-pip
RUN pip install -r requirements.txt
CMD python /app/app.py FROM python:3.9.2-alpine
COPY app.py /app
RUN apt-get update && apt-get -y install python-pip
RUN pip install -r requirements.txt
CMD python /app/app.py FROM python:3.9.2-alpine
RUN apt-get update && apt-get -y install python-pip
RUN pip install -r requirements.txt
COPY app.py /app
CMD python /app/app.py 압축 파일 가져오기
sudo apt install git
git clone https://github.com/brayanlee/webapp.git

압축 파일이 있는 곳으로 프롬프트를 이동
cd webapp
ls 명령으로 압축 파일이 있는지 확인

Dockerfile이 저장될 디렉토리를 생성
mkdir dockerfiles
Dockerfile 생성하고 작성
nano dockerfiles/Dockerfile
FROM ubuntu:latest
RUN apt-get update && apt-get -y install apache2 vim curl
ADD webapp.tar.gz /var/www/html
WORKDIR /var/www/html
EXPOSE 80
CMD /usr/sbin/apachectl -D FOREGROUND
이미지 빌드
docker build -t webapp:8.0 -f ./dockerfiles/Dockerfile .
컨테이너 생성
docker run -dit -p 8201:80 --name webapp8 webapp:8.0
압축된 파일이 해제되었는지 확인
docker exec -it webapp8 /bin/bash
ls

이전에 사용한 도커 파일을 수정(nano dockerfiles/Dockerfile)
FROM ubuntu:latest
RUN apt-get update && apt-get -y install apache2 vim curl && apt-get clean -y && apt-get autoremove -y && rm -rfv /var/lib/apt/lists/* /tmp/* /var/tmp/*
ADD webapp.tar.gz /var/www/html
WORKDIR /var/www/html
EXPOSE 80
CMD /usr/sbin/apachectl -D FOREGROUND
이미지 빌드
docker build -t webapp:9.0 -f ./dockerfiles/Dockerfile .
이미지 크기 확인
docker images
