로컬 환경에서 도커가 깔려있다는 전제하에 다음 내용을 진행하겠다. docker-compose up을 통해 빌드하고 실행시킬 예정이다.
1. docker-compose up 빌드해보기
- 프로젝트 최상단 루트에 Dockerfile 을 추가한다.
- Dockerfile
FROM python:3.8
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/
- 프로젝트 최상단 루트에 docker-compose.yml 을 추가한다.
- docker-compose.yml
version: '3'
services:
web:
build:
context: .
dockerfile : Dockerfile
command : python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code/
ports:
- "8000:8000"
- 도커로 서버를 실행해본다.
- 127.0.0.1:8000 으로 들어가본다.
docker-compose up -build
2. Docker와 Nginx + Django + Gunicorn 으로 실행하기
- gunicorn 설치.
pipenv install gunicorn
- nginx 연결과정 1 - nginx.conf 설정
- config > nginx > nginx.conf 생성
* 주의사항 : nas 가 기본적으로 80포트를 사용하기 때문에 nginx 는 100번 포트를 사용했다
- nginx.conf
upstream web {
ip_hash;
server web:8000;
}
server {
location /static/ {
alias /code/static;
}
location / {
proxy_pass http://web/;
}
listen 100;
server_name localhost;
}
- nginx 연결과정 2
- 프로그램 최상위 루트에 생성한 docker-compose.yml 수정하여 nignx를 도커에 실행
- docker-compose.yml
version: '3'
services:
nginx:
image: nginx:latest
ports:
- "10:100"
volumes:
- .:/code
- ./config/nginx:/etc/nginx/conf.d
depends_on:
- web
web:
build:
context: .
dockerfile : Dockerfile
command : gunicorn config.wsgi:application --bind 0.0.0.0:8000
volumes:
- .:/code/
ports:
- "8000"
- 빌드해서 실행해본다.
docker-compose up --build
- 위 명령어로 빌드하여 웹페이지에서 실행이 되었는지 127.0.0.1을 쳐본다 (포트없이)
- 터미널에 보여지는 내용은 다음과 같다.
3. github에 업로드
- 깃허브에 적당한 이름의 레포지토리를 만들고 푸쉬하면 된다.
- 추후 시놀로지에서 깃허브에서 풀땡겨서 가져와야 한다.
git init
git remote add origin https://github.com/XXX/XXX.git
git add .
git commit -m "first commit"
git push origin master
다음화에서는 로컬에서 만든 프로젝트를 시놀로지 DS920+ 에 배포하는 내용을 다룰 예정이다.
2021.12.07 - [분류 전체보기] - 3. Synology에 배포하기 (docker, nginx, django, gunicorn)
3. Synology에 배포하기 (docker, nginx, django, gunicorn)
마지막 챕터로 시놀로지에 배포하려고 한다. 이전 글을 꼼꼼히 확인해주셨으면 아시겠지만 이 챕터에서 필요한건 synology에서 ddns, ssh 설정 docker, gitserver 설치 과정이 필요하고 자세한 설정 방법
cha2hyun.tistory.com
'Synology > 1. NAS를 웹서버로 사용하기' 카테고리의 다른 글
6. [시놀로지에 웹서버 띄우기] vscode ssh-remote 로 nas로 원격 접근하여 코딩하기 (0) | 2021.12.08 |
---|---|
5. [시놀로지에 웹서버 띄우기] nginx https 설정하기 (0) | 2021.12.08 |
4. [시놀로지에 웹서버 띄우기] Synology에 장고 웹서버 배포하기 (docker, nginx, django, gunicorn) (0) | 2021.12.07 |
2. [시놀로지에 웹서버 띄우기] DS920+ 설정과 Django 프로젝트 생성 (docker, nginx, django, gunicorn) (0) | 2021.12.07 |
1. [시놀로지에 웹서버 띄우기] 시놀로지DS920+ 도입 과정 (0) | 2021.12.07 |