Notice
Recent Posts
Recent Comments
Link
반업주부의 일상 배움사
Nodejs + Docker + ECR 배포 본문
반응형
[ Local: Nodejs - express ]
1. index.js
const express = require("express");
const app = express();
app.get("/", (req, res) => {
res.send("This is my express app");
});
app.get("/me", (req, res) => {
res.send("Hi I am Laith");
});
app.listen(3000, () => {
console.log("listening");
});
2. package.json
{
"name": "project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1"
}
}
3. 모듈 설치 및 실행
$ npm i
$ node index.js
4. 브라우저에서 http://localhost:3000/ 접속
[ Local: Docker ]
1. Dockerfile
FROM node:16.13.1
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
EXPOSE 3000
CMD [ "node", "index.js" ]
2. 빌드 및 확인
$ docker build -t express-app .
$ docker images
3. 실행
$ docker run -p 5678:3000 ffe4a10e47e7
4. 브라우저에서 http://localhost:5678/ 접속
[ AWS - ECS > ECR ]
1. 기본 설정에 리포지토리 이름만 넣어서 생성
2. 리포지토리 선택 > 푸시 명령 보기 버튼 클릭
3. 터미널에서 단계별 명령어 실행 > 이미지 생성
[ EC2 ]
1. 도커 설치 (Ubuntu 18.04)
$ apt-get update
$ apt-get upgrade -y
$ apt-get install -y ca-certificates curl software-properties-common apt-transport-https gnupg lsb-release
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
$ apt-get update
$ apt-get install docker-ce -y
$ apt-cache policy docker-ce
$ docker -v
2. AWS CLI 설치
$ apt-get install awscli -y
$ aws configure
$ aws ecr describe-images --repository-name express-app
$ aws ecr get-login --region ap-northeast-2 <= 결과 값을 복사해서 다시 실행 (만약 에러가 난다면 -e none 삭제 후 시도)
3. ECR의 이미지 다운로드
$ docker pull {리포지토리 URI}:latest
예) docker pull 736283784849.dkr.ecr.ap-northeast-2.amazonaws.com/express-app:latest
$ docker images
4. 도커 실행
$ docker run -p 3000:3000 {이미지 ID}
5. 브라우저에서 http://3.32.115.111:3000/ 접속 (EC2 IP)
영어, 중국어 공부중이신가요?
홈스쿨 교재. 한 권으로 가족 모두 할 수 있어요!
반응형
LIST
'IT 인터넷 > Docker' 카테고리의 다른 글
[Docker] 단숨에 도커 설치 및 Hello World 튜토리얼 따라하기 (0) | 2020.07.27 |
---|
Comments