스펠체크

Docker 파일

조회: 195 댓글: 0개 2023.11.08 14:38 수요일

Dockerfile

#alpine 리눅스 기반
FROM alpine:latest

#타임존 다운 받고 환경변수 설정
RUN apk add tzdata
ENV TZ=Asia/Seoul

#nginx, python3, pip다운
#py3-mysqlclient 없으면 pip mysqlclient 에러남
#python3-dev gcc libc-dev 없으면 gcc 에러
#libffi-dev 없으면 ffi 에러
RUN apk add nginx python3-dev gcc libc-dev libffi-dev python3 py3-pip py3-mysqlclient

#내 가상호스트가 설정된 default.conf를 경로로 복사
#왜 /etc/nginx/sites-available이 아닌지 찾아봤는데 몰?루
ADD default.conf /etc/nginx/http.d/default.conf
#ADD nginx.conf /etc/nginx/nginx.conf

#현재 폴더 내용을 경로로 복사
ADD ./ /var/www/spell
WORKDIR /var/www/spell
#python 모듈 다운로드
RUN pip install -r requirements.txt
#권한 추가
RUN chmod +x entrypoint.sh

#포트 연결
EXPOSE 80
EXPOSE 443

#./안 붙이니까 안됨 ㅋㅋ;
ENTRYPOINT ./entrypoint.sh

default.conf

server {
  listen 80;
  server_name _;

  location = /favicon.ico { access_log off; log_not_found off; }

  location /static/ {
    alias /var/www/spell/static/;
  }

  location / {
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_pass http://unix:/tmp/daphne_spell.sock;
  }
  location /ws/ {
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_redirect off;
    proxy_pass http://unix:/tmp/daphne_spell.sock;
  }
}

entrypoint.sh

#!/bin/sh

nginx
python3 manage.py migrate
daphne -u /tmp/daphne_spell.sock  config.asgi:application
captcha