Coder Social home page Coder Social logo

crud_nodejs's People

Contributors

yooonmyong avatar

Stargazers

 avatar

Watchers

 avatar

crud_nodejs's Issues

Docker로 만든 이미지를 AWS를 이용해 웹 상에 배포하기

시작 전 AWS에서 발급받은 key(.pem 파일)와
Dockerfile은 경로를 통일 시키는 것을 추천한다.
(아래에서는 통일 시키지 않아서 중간에 key파일을 Dockerfile의 경로로 옮겼다.)

아래 과정은 새로운 키를 발급받아, IP주소를 받았을 때 그 주소에 ubuntu를 연결하여 실행하는 과정이다.
Docker 이미지는 사전에 만들었으므로 반복할 필요가 없다. (Dockerfile 내용 변경 시마다 이미지를 새로 구축)

<사전준비>

----------Linux 환경------------

리눅스계정명@DESKTOP-M8BFCT1:/mnt/c/Users/로컬컴퓨터사용자명$ cd /mnt/c/Users/로컬컴퓨터사용자명/Documents/crud_nodejs

발급받은 key파일과 Dockerfile이 있는 경로, 여기가 ubuntu의 시작점이다.

$ sudo ssh -i '/mnt/c/Users/로컬컴퓨터사용자명/Documents/crud_nodejs/crud_nodejs.pem' [email protected]

3.139.122.190은 AWS에서 발급받은 key에 탄력적 IP를 할당받아 고정시킨 IP이다
추후 연결이 완료되면, 모든 컴퓨터에서 해당 IP주소를 입력하면 내가 배포한 웹 서비스에 누구나 접속이 가능해진다.
만일 이 IP주소가 바뀌는 일이 생길 경우, 바뀐 IP주소로 다시 ubuntu를 연결하여 이 과정을 다시 실행해야 한다.
1 IP : 1 ubuntu 관계

----------ubuntu 환경------------

Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 5.4.0-1029-aws x86_64)
~ (생략, 정상 접속 시 ubuntu 문서 내용이 좌르륵 나옴)
ubuntu@ip-172-31-22-255:~$ sudo apt-get update
ubuntu@ip-172-31-22-255:~$ sudo apt-get install curl
ubuntu@ip-172-31-22-255:~$ curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
ubuntu@ip-172-31-22-255:~$ sudo apt-get install -y nodejs
ubuntu@ip-172-31-22-255:~$ npm -v
6.14.8
ubuntu@ip-172-31-22-255:~$ node -v
v10.23.0
ubuntu@ip-172-31-22-255:~$ sudo npm install -g npm
ubuntu@ip-172-31-22-255:~$ curl -fsSL https://get.docker.com/ | sudo sh
ubuntu@ip-172-31-22-255:~$ sudo usermod -aG docker $USER
ubuntu@ip-172-31-22-255:~$ sudo curl -L 
"https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" 
-o /usr/local/bin/docker-compose
ubuntu@ip-172-31-22-255:~$ sudo chmod +x /usr/local/bin/docker-compose
ubuntu@ip-172-31-22-255:~$ docker version
ubuntu@ip-172-31-22-255:~$ docker-compose version
ubuntu@ip-172-31-22-255:~$ sudo reboot
ubuntu@ip-172-31-22-255:~$ Connection to 3.139.122.190 closed by remote host.
Connection to 3.139.122.190 closed.

해당 ubuntu에 npm, nodejs, docker 등을 설치 중
reboot 후 ubuntu에 재접속한 뒤,

ubuntu@ip-172-31-22-255:~$ sudo docker login
Login with your Docker ID to push and pull images from Docker Hub. 
If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: (Docker 계정 아이디)
Password: (Docker 계정 비번)
Login Succeeded
ubuntu@ip-172-31-22-255:~$ docker push (Docker 계정 아이디)/crudnodejs:crud
The push refers to repository [docker.io/(Docker 계정 아이디)/crudnodejs]
An image does not exist locally with the tag: (Docker 계정 아이디)/crudnodejs 
(이미지 push 실패..)
crudnodejs:crud 란 ubuntu 아닌 linux 단에서 Dockerfile이 존재하는 경로로 이동해 만들어둔 Docker 이미지명 및 태그명

bash창으로는 이미지 push가 원활하지 않아서
Docker desktop 애플리케이션에서 수동으로 push함
지금 하는 과정이 만든 이미지를 Docker hub에 push하는 과정이어서
(마치 Git hub에 push하는 과정처럼)
애플리케이션으로 해도 충분함
(ubuntu와 애플리케이션을 git bash와 source tree 같은 관계로 생각하면 편하다.)

ubuntu@ip-172-31-22-255:~$ sudo docker pull (Docker 계정 아이디)/crudnodejs:crud
crud: Pulling from (Docker 계정 아이디)/crudnodejs
~ 
(뭐가 좌르륵 뜨면서 pull을 한다. 조금 시간이 걸림)

여기까지 하면 docker hub에 올라간 이미지를, AWS key와 연결된 ubuntu 계정에 연결 완료했다

ubuntu@ip-172-31-22-255:~$ sudo docker run -t -i -p 3000:3000 (Docker 계정 아이디)/crudnodejs:crud
2020-11-20T15:43:11: PM2 log: Launching in no daemon mode
2020-11-20T15:43:11: PM2 log: App [www:0] starting in -fork mode-
2020-11-20T15:43:11: PM2 log: App [www:0] online

연결 완료!
3.139.122.190:3000 으로 접속하면 이제 내가 배포한 웹 사이트를 사용할 수 있다

<연결한 모습>

캡처

웹에서의 반응에 따라

GET / 200 10.731 ms - 218
GET /stylesheets/style.css 200 3.051 ms - 119
GET /favicon.ico 404 1.874 ms - 826
GET /mainTODO 200 2.082 ms - 5734
GET /mainTODO 304 1.782 ms - -
GET /createTODO 200 2.179 ms - 2112
GET /createTODO 304 1.320 ms - -
POST /createTODO 302 12.422 ms - 60
GET /mainTODO 304 2.437 ms - -
~

ubuntu 콘솔에서 이런 식으로 뜬다

참고 글

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.