협업을 위한 Docker Image 만들기

HY🥗·2022년 10월 7일
2

research

목록 보기
4/8

발단

벨로그를 이용하면서 시리즈 관련 이슈를 발견했다. 시리즈를 수정, 삭제 하여도 로그아웃 했다가 다시 로그인 하기 전까지 시리즈 목록에서 반영이 되지 않는 이슈였는데, 이를 메일과 트위터로 문의했지만 아무런 답변을 받지 못 했다. 딱히 당장 사용에 문제가 되는 이슈는 아니었지만 다른 블로그로 갈아탈까 고민하면서 다른 플랫폼을 비교해보다 그럼 만들고 싶은 블로그를 만들면 되지 않나 하는 생각이 들었다.

협업 시 불편함

프론트엔드 1명, 백엔드 2명으로 팀을 꾸려 블로그를 만들기로 했다. 네이버 블로그와 벨로그의 장점을 합쳐 블로그 플랫폼을 만들려고 했는데, 이전에 프로젝트에서 프론트엔드와 백엔드를 나눠서 작업할 때 불편했던 적이 떠올랐다. 프론트엔드 담당자가 테스트를 할 때 서버가 필요한데, 서버를 올리고 하는 걸 불편해했다.
이를 개선할 방법을 찾다 devdynam0507님의 docker로 백엔드 개발 환경 만들기 포스트를 읽고 docker image를 만들기로 했다.

Docker Base Image 만들기

ubuntu image에 git, nodejs 설치

❯ docker run -it --name navelog ubuntu:latest bash
root@85b6436a0d44:/# git
bash: git: command not found
root@85b6436a0d44:/# apt-get update
Get:1 http://ports.ubuntu.com/ubuntu-ports jammy InRelease [270 kB]
...      
Get:17 http://ports.ubuntu.com/ubuntu-ports jammy-security/restricted arm64 Packages [138 kB]         
Fetched 22.1 MB in 7s (3342 kB/s)                                                     
Reading package lists... Done
root@85b6436a0d44:/# apt-get install -y git
Reading package lists... Done
...
Running hooks in /etc/ca-certificates/update.d...
done.
root@85b6436a0d44:/# git --version
git version 2.34.1
root@85b6436a0d44:/# apt-get install -y nodejs
Reading package lists... Done
...
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...
root@85b6436a0d44:/# node
Welcome to Node.js v12.22.9.

Docker image commit 후 push

❯ docker container ls
CONTAINER ID   IMAGE           COMMAND   CREATED         STATUS         PORTS     NAMES
85b6436a0d44   ubuntu:latest   "bash"    4 minutes ago   Up 4 minutes             navelog
❯ docker ps
CONTAINER ID   IMAGE           COMMAND   CREATED          STATUS          PORTS     NAMES
85b6436a0d44   ubuntu:latest   "bash"    10 minutes ago   Up 10 minutes             navelog
❯ docker commit 85b6436a0d44 haejeonghy/navelog:1.0
sha256:1056db8eadf74c197c0ff26752ba2ae232fc610c6b4c65debab509ae9ad14028
❯ docker push haejeonghy/navelog:1.0
The push refers to repository [docker.io/haejeonghy/navelog]
b82e793001d6: Pushed 
ede2ae06e2f4: Mounted from haejeonghy/test 
1.0: digest: sha256:93adc032819dbd48b8fd3c5815e71d417cc450c065f79aa99f1388f8c95bcd61 size: 741

docker hub에서 푸쉬 된 image 확인

docker hub에 푸쉬한 image container로 띄워서 확인

❯ docker run -it --name navelog2 haejeonghy/navelog:1.0 bash
root@ed7c51c914a2:/# git --version
git version 2.34.1 

만들었던 image의 깃 버전과 같다.

프로젝트 pull 해서 image에 프로젝트 다운로드 및 npm 설치

root@ed7c51c914a2:/home/navelog# git pull https://github.com/haejeonghy/navelog
remote: Enumerating objects: 27, done.
remote: Counting objects: 100% (27/27), done.
remote: Compressing objects: 100% (24/24), done.
remote: Total 27 (delta 1), reused 24 (delta 1), pack-reused 0
Unpacking objects: 100% (27/27), 149.37 KiB | 1.49 MiB/s, done.
From https://github.com/haejeonghy/navelog
 * branch            HEAD       -> FETCH_HEAD
root@ed7c51c914a2:/home/navelog# #
root@ed7c51c914a2:/home/navelog# ls
README.md  client  document  server
root@ed7c51c914a2:/home/navelog# cd server
root@ed7c51c914a2:/home/navelog/server# ls
README.md      package-lock.json  src   tsconfig.build.json
nest-cli.json  package.json       test  tsconfig.json
root@ed7c51c914a2:/home/navelog/server# npm i 
bash: npm: command not found
root@ed7c51c914a2:/home/navelog/server# npm
bash: npm: command not found
root@ed7c51c914a2:/home/navelog/server# apt-get install npm
Reading package lists... Done
Building dependency tree... Done
... 
root@ed7c51c914a2:/home/navelog/server# npm i
added 688 packages, and audited 689 packages in 14s

90 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
root@ed7c51c914a2:/home/navelog/server# npm run start

> server@0.0.1 start
> nest start

[Nest] 4776  - 10/07/2022, 5:31:55 AM     LOG [NestFactory] Starting Nest application...
[Nest] 4776  - 10/07/2022, 5:31:55 AM     LOG [InstanceLoader] AppModule dependencies initialized +23ms
[Nest] 4776  - 10/07/2022, 5:31:55 AM     LOG [RoutesResolver] AppController {/}: +3ms
[Nest] 4776  - 10/07/2022, 5:31:55 AM     LOG [RouterExplorer] Mapped {/, GET} route +2ms
[Nest] 4776  - 10/07/2022, 5:31:55 AM     LOG [NestApplication] Nest application successfully started +0ms

docker push

❯ docker container ls
CONTAINER ID   IMAGE                    COMMAND   CREATED          STATUS          PORTS     NAMES
ed7c51c914a2   haejeonghy/navelog:1.0   "bash"    12 minutes ago   Up 12 minutes             navelog2
❯ docker commit ed7c51c914a2 haejeonghy/navelog:1.1
sha256:77a58bf563e82f5d256d6c94621bafbd5f66bd540b22b4b3d869ff307ea09c4b
❯ docker login
Authenticating with existing credentials...
Login Succeeded

Logging in with your password grants your terminal complete access to your account. 
For better security, log in with a limited-privilege personal access token. Learn more at https://docs.docker.com/go/access-tokens/
❯ docker push haejeonghy/navelog:1.1
The push refers to repository [docker.io/haejeonghy/navelog]
708e8d4ba1fb: Pushed 
b82e793001d6: Layer already exists 
ede2ae06e2f4: Layer already exists 
1.1: digest: sha256:4460797e52006cd402ed3f0482a9aff7b853e496f2a9dddea9fa1e42d80b7247 size: 954

새 이미지 run

❯ docker run -it --name navelog3 haejeonghy/navelog:1.1 bash
root@818ef39e45cd:/# ls
bin  boot  dev  etc  home  lib  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@818ef39e45cd:/# cd home
root@818ef39e45cd:/home# ls
navelog
root@818ef39e45cd:/home# cd navelog/
root@818ef39e45cd:/home/navelog# ls
README.md  client  document  server
root@818ef39e45cd:/home/navelog# cd server
root@818ef39e45cd:/home/navelog/server# ls
README.md  nest-cli.json      package.json  test                 tsconfig.json
dist       package-lock.json  src           tsconfig.build.json
root@818ef39e45cd:/home/navelog/server# npm i
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@angular-devkit/core@14.2.2',
npm WARN EBADENGINE   required: {
npm WARN EBADENGINE     node: '^14.15.0 || >=16.10.0',
npm WARN EBADENGINE     npm: '^6.11.0 || ^7.5.6 || >=8.0.0',
npm WARN EBADENGINE     yarn: '>= 1.13.0'
npm WARN EBADENGINE   },
npm WARN EBADENGINE   current: { node: 'v12.22.9', npm: '8.5.1' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@angular-devkit/schematics@14.2.2',
npm WARN EBADENGINE   required: {
npm WARN EBADENGINE     node: '^14.15.0 || >=16.10.0',
npm WARN EBADENGINE     npm: '^6.11.0 || ^7.5.6 || >=8.0.0',
npm WARN EBADENGINE     yarn: '>= 1.13.0'
npm WARN EBADENGINE   },
npm WARN EBADENGINE   current: { node: 'v12.22.9', npm: '8.5.1' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@angular-devkit/schematics-cli@14.2.2',
npm WARN EBADENGINE   required: {
npm WARN EBADENGINE     node: '^14.15.0 || >=16.10.0',
npm WARN EBADENGINE     npm: '^6.11.0 || ^7.5.6 || >=8.0.0',
npm WARN EBADENGINE     yarn: '>= 1.13.0'
npm WARN EBADENGINE   },
npm WARN EBADENGINE   current: { node: 'v12.22.9', npm: '8.5.1' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@angular-devkit/core@14.2.1',
npm WARN EBADENGINE   required: {
npm WARN EBADENGINE     node: '^14.15.0 || >=16.10.0',
npm WARN EBADENGINE     npm: '^6.11.0 || ^7.5.6 || >=8.0.0',
npm WARN EBADENGINE     yarn: '>= 1.13.0'
npm WARN EBADENGINE   },
npm WARN EBADENGINE   current: { node: 'v12.22.9', npm: '8.5.1' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@angular-devkit/schematics@14.2.1',
npm WARN EBADENGINE   required: {
npm WARN EBADENGINE     node: '^14.15.0 || >=16.10.0',
npm WARN EBADENGINE     npm: '^6.11.0 || ^7.5.6 || >=8.0.0',
npm WARN EBADENGINE     yarn: '>= 1.13.0'
npm WARN EBADENGINE   },
npm WARN EBADENGINE   current: { node: 'v12.22.9', npm: '8.5.1' }
npm WARN EBADENGINE }
npm WARN deprecated superagent@8.0.2: Please use v8.0.0 until https://github.com/visionmedia/superagent/issues/1743 is resolved

added 688 packages, and audited 689 packages in 9s

90 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
root@818ef39e45cd:/home/navelog/server# npm run start

> server@0.0.1 start
> nest start

[Nest] 66  - 10/07/2022, 5:39:29 AM     LOG [NestFactory] Starting Nest application...
[Nest] 66  - 10/07/2022, 5:39:29 AM     LOG [InstanceLoader] AppModule dependencies initialized +18ms
[Nest] 66  - 10/07/2022, 5:39:29 AM     LOG [RoutesResolver] AppController {/}: +3ms
[Nest] 66  - 10/07/2022, 5:39:29 AM     LOG [RouterExplorer] Mapped {/, GET} route +2ms
[Nest] 66  - 10/07/2022, 5:39:29 AM     LOG [NestApplication] Nest application successfully started +1ms

이렇게 하자 node module 설치 후 바로 서버를 올릴 수 있었다. 서버를 컨테이너에 올려 테스트 할 때 깃헙 최신 버전을 pull 받아서 실행하면 되지 않을까? 브랜치를 바꿔가면서? 그런데 여기까지 생각해보니까 프론트와 서버 모두 nodeJS 환경이고, 지난 프로젝트 때는 프론트가 리액트 네이티브라 그랬지 이번엔 리액트라 별 상관이 없나 하는 생각도 든다.
그래... 배포할 때는 써먹지 않을까...

참고 문헌

https://velog.io/@devdynam0507/Docker%EB%A1%9C-%ED%8C%80%EC%9B%90%EB%93%A4%EC%97%90%EA%B2%8C-%EA%B3%B5%ED%86%B5%EB%90%9C-%EB%B0%B1%EC%97%94%EB%93%9C-%EA%B0%9C%EB%B0%9C%ED%99%98%EA%B2%BD-%EC%A0%9C%EA%B3%B5%ED%95%B4%EC%A3%BC%EA%B8%B0

profile
사실은 공부를 비밀스럽게 하고 싶었다

0개의 댓글