Nginx를 프록시 서버(Ubuntu)로 사용하여 Docker로 NodeJS Restful 애플리케이션 배포
Docker를 사용하여 컨테이너 내에서 이러한 애플리케이션을 실행하고 있습니다. NodeJS는 크랙하기 어려운 것으로 판명되었습니다...하지만 아쉽게도 마침내 크랙되었습니다. 이것이 내가 마침내 NodeJS RESTFUL 앱을 도킹하고 실행하는 방법입니다.$ mkdir <foldername> && cd <foldername> npm 또는 yarn를 사용하여 새 nodejs 앱을 만듭니다.$ npm init <application name> $ npm install express --save package.json 파일, node_modules 폴더 및 일부 잠금 파일이 있어야 합니다. 다음을 실행하여 앱 디렉토리 터미널 창/셸 아래에 이 명령의 기본 파일을 만듭니다. $ touch <filename>.js5.package.json 파일을 편집합니다. 스크립트 정의 아래에 존재하지 않는 경우 이것을 추가하고 파일을 저장하십시오."scripts": {
"start": "node <mainfile>"
}
$ touch Dockerfile$ touch docker-compose.yml # obtain the node image
FROM node
# change to the working directory
WORKDIR <directory_name>
#move the package file to the current working directory
COPY package*.json ./
# install the depedencies
RUN npm install
COPY . .
# run the app
CMD [ "node", <mainfile> ]
mkdir nginx && cd nginx && touch default.conf environment name 및 port는 docker-compose.yml 파일에서 가져와서 정의해야 합니다.http {
upstream backend {
server <environment_name: port>
}
server {
location / {
proxy_pass http://backend;
}
}
}
docker-compose.yml를 편집하십시오.versions: '3',
services:
nginx_server:
image: nginx #image of the nginx
volumes:
- './nginx/default.conf:/etc/nginx/nginx.conf'
ports:
- '8000:80'
#define the node app container
app:
container_name: <container name>
build:
context: .
dockerfile: Dockerfile #name of the dockerfile we created
ports:
- '3000:80' #docker container port = 3000, host port= 80
environment:
- APPID=3000
Reference
이 문제에 관하여(Nginx를 프록시 서버(Ubuntu)로 사용하여 Docker로 NodeJS Restful 애플리케이션 배포), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/nsengiyunva/deploy-a-nodejs-restful-application-with-docker-using-nginx-as-the-proxy-server-ubuntu--m8j텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)