개요
Django + Gunicorn에 대한 docker image를 생성할 것입니다.
실행 전 Django 및 Gunicorn 설치 후 UI 띄우는 것 까지 진행하고 오십시오.
https://twodeveloper.tistory.com/105
[Django] Django Install
개요 Django를 설치하고 MariaDB와 연동 및 Gunicorn을 통해 bind 시켜 Web UI에 띄우는 것 까지 진행하도록 하겠습니다. 진행환경 OS : CentOS 7.6 Python : 3.6 Django : MariaDB : Django Install 1. Python In..
twodeveloper.tistory.com
1. requirement.txt을 생성합니다.
(venv) pip freeze > requirement.txt
2. Dockerfile을 구성합니다.
FROM python:3.6
ENV PYTHONUNBUFFERED 1
RUN mkdir /djangoproject
ADD . /djangoproject
WORKDIR /djangoproject
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
EXPOSE 8000
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "djangoproject.wsgi:application"]
3. Docker image를 생성합니다.
* Dockerfile을 생성한 위치에서 실행합니다.
$ docker image build -t djangoproject .
4. Docker image 생성 확인
$ Docker image ls
5. 생성한 Docker Image를 통해 실행
$ docker run -it -p 8000:8000 djangoproject:latest
* 여기서 Issue가 발생하였습니다.
docker: Error response from daemon: driver failed programming external connectivity on endpoint zealous_wozniak (f1295c80760a64148439079d7f95bf8d03591daa0ca5f0e6ff2b21beb10e7773): (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 8000 -j DNAT --to-destination 172.17.0.2:8000 ! -i docker0: iptables: No chain/target/match by that name.
확인 결과 방화벽 포트 충돌로 인한 Issue 였고 다음과 같이 해결하였습니다.
$ sudo iptables -t filter -F
$ sudo iptables -t filter -X
$ sudo systemctl restart docker
6. Django Web UI
* http://[server IP]:8000 로 접속하면 다음과 같이 Django UI가 뜨는 것을 확인할 수 있습니다.
'DevOps > Docker' 카테고리의 다른 글
[Docker] Docker Compose Install (0) | 2022.09.21 |
---|---|
[Docker] CentOS에서 Docker Install (0) | 2022.09.21 |
[Docker] 이미지 (0) | 2021.09.15 |
[Docker] Web Server 구축 (0) | 2021.09.15 |
[Docker] Container 실행 (0) | 2021.09.15 |