-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] 백엔드 NGINX, MySQL, Network Docker 환경 설정 #30
Conversation
@@ -0,0 +1,5 @@ | |||
FROM nginx | |||
|
|||
COPY nginx.conf /etc/nginx/conf.d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
프로젝트의 nginx 설정값들을 도커 내부 nginx 설정파일에 옮기는 작업인가요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
정확합니다!!
- 3306:3306 | ||
environment: | ||
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 환경변수들은 어디서 가져와서 사용되는 것인가요? DOCKER_SERVER_IMAGE는 깃헙 레포지토리에 등록된 환경변수에서 가져오는 것으로 아는데 이것은 로컬 환경변수를 가져오는 것일까요?
또 로컬에서 개발시 사용한다면 이 환경변수 값을 로컬 MYSQL에 맞게 바꿔줘야 하는게 맞나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Github Secret에서 해당 환경변수를 저장해놓고 셸스크립트를 이용해 .env 파일을 만드는 작업을 하고 있습니다.
로컬에서 개발할 때 제가 노션에 올려드린 .env 파일이 필요할 것 같습니다. 왜냐면 도커에 해당 환경변수를 넣어 아예 똑같게 세팅하는 거라 로컬의 MySQL과 도커의 MySQL는 완전 분리되어 있다고 보시면 될 것 같습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
로컬에서 개발할 때는, 환경변수를 다 담아놓은 docker-compose.local.yml
같은 파일을 만들어서 사용할 수 있도록하는건 어떠신가요? 아래처럼요!
environment:
MYSQL_ROOT_PASSWORD: test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
좋습니다!! 변경하도록 할게요!!
(+추가) 적용 완료했습니다!!
COPY package*.json ./ | ||
|
||
RUN npm install | ||
|
||
COPY . . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
npm install
하는거면 package.json
파일만 복사해도 되지 않을까요?
그리고 패키지 관련 파일만 copy하고, install 후에 다시 모든 파일을 copy하는 이유가 궁금합니다! 한번에 다 copy하는 것과 차이가 있나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
buildx를 정확하게 파악하지 못해서 npm ci가 되지 않아 npm install을 진행하고 있습니다. npm ci를 하는 것이 최종 목표라 일단은 package*.json
으로 해놨습니다.
위와 같이 따로 분리한 이유는 docker image를 만드는 시간을 조금 더 최적화하기위해서입니다. Docker의 경우 image를 생성할 때 layer라는 개념을 사용하고 있고, 이를 이용해서 docker image 생성에 대한 최적화를 할 수 있습니다.
간단히 설명하면 docker image를 생성할 때, Dockerfile의 명령어는 각각 수행하면서 새로운 layer를 생성하게 됩니다. 그리고 다음번에 동일한 Dockerfile을 이용하여 image를 생성하는 경우, 해당 명령어가 이전에 생성된 layer(캐싱되어 있는 친구)를 그대로 사용하기도 합니다. 만약 내용이 변경되었다면 새로 layer를 생성하고요.
만약 분리되어 있지 않다고 하면 package*.json
이 변경되지도 않았는데 src
폴더의 내용이 변경되었다는 이유로 npm install을 다시 진행하게 됩니다. 그러면 매번 시간이 오래 걸리겠죠..?? 그래서 나눈 겁니다!!
@@ -0,0 +1,13 @@ | |||
|
|||
upstream backend-server { | |||
server moyeo-server:3000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기에 서비스 네임이 들어가는 걸로 알고 있었는데, 컨테이너 네임이 들어가는 건가 보네요..??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 그렇다고 합니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨어요.
다만 로컬 환경에서도 도커를 사용해 개발한다면, 도커 컴포즈파일 구분이 필요할 것 같아요.
또 개발용 서버하나 뿐이라면 괜찮겠지만, 백엔드 CI에서 테스트시 전달해주어야 하는 환경변수들도 시크릿에 등록해주어야 할 것 같은데, secrets.BACKEND_ENVIRONMENT
이름이 명확하지 않은 것 같아요.
|
체크 리스트
작업 내역
문제 상황과 해결
localhost
로 들어가면 아래와 같이 로드밸런싱이 안되지만127.0.0.1
로 들어가면 잘된다… 왜지….?비고
링크: https://bill1224.tistory.com/359
도커 운영환경을 위한 Nginx Dockerfile 작성하기: [https://velog.io/@hong_tae/도커-운영환경을-위한-Nginx-Dockerfile-작성하기](https://velog.io/@hong_tae/%EB%8F%84%EC%BB%A4-%EC%9A%B4%EC%98%81%ED%99%98%EA%B2%BD%EC%9D%84-%EC%9C%84%ED%95%9C-Nginx-Dockerfile-%EC%9E%91%EC%84%B1%ED%95%98%EA%B8%B0)
컨테이너 환경 nginx에서 컨테이너 환경의 다른 어플리케이션 접근을 위한 네트워크 구성: https://ondemand.tistory.com/363
Docker 네트워크 사용법: https://www.daleseo.com/docker-networks/
로컬 개발환경 Docker 사용하기: https://labs.brandi.co.kr/2021/01/20/hwangsg.html
차근차근 해보는 Docker 개발환경 세팅: [https://l4279625.tistory.com/entry/차근차근-해보는-Docker-개발환경-세팅-방법?category=1044263?category=1044263
docker를 이용해 개발 환경 구축하기 1편
docker를 이용해 개발 환경 구축하기 2편
local 개발 환경의 필요성