๋„์ปค Docker ๐Ÿณ

๊น€์•„๋ฌด๊ฐœยท2023๋…„ 7์›” 22์ผ
0

ubuntu

๋ชฉ๋ก ๋ณด๊ธฐ
13/20
post-custom-banner

๋ณด๊ณ  ๋ฐฐ์šด ์ธ๊ฐ•

1. ๋„์ปค๋ž€ ?

์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ

์‘์šฉํ”„๋กœ๊ทธ๋žจ์„ ๋” ์‰ฝ๊ฒŒ ๋งŒ๋“ค๊ณ , ๋ฐฐํฌํ•˜๊ณ  ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋„๋ก ์„ค๊ณ„๋œ ๋„๊ตฌ์ด๋ฉฐ

์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋ฐ˜์˜ ์˜คํ”ˆ ์†Œ์Šค ๊ฐ€์ƒํ™” ํ”Œ๋žซํผ์ด๋‹ค.


์ผ๋ฐ˜ ์ปจํ…Œ์ด๋„ˆ ๊ฐœ๋…์—์„œ ๋ฌผ๊ฑด์„ ์†์‰ฝ๊ฒŒ ์šด์†กํ•ด์ฃผ๋Š” ๊ฒƒ์ฒ˜๋Ÿผ

์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ™˜๊ฒฝ์— ๊ตฌ์• ๋ฐ›์ง€ ์•Š๊ณ  ์†์‰ฝ๊ฒŒ ๋ฐฐํฌ ๊ด€๋ฆฌ๋ฅผ ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค€๋‹ค.


์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋ฐ˜ ๋ฐฐํฌ ๋ฐฉ์‹์€

๊ตฌ๊ธ€์„ ๋น„๋กฏํ•ด ๋Œ€๋ถ€๋ถ„์˜ ์„œ๋น„์Šค ํšŒ์‚ฌ๊ฐ€ ์ปจํ…Œ์ด๋„ˆ๋กœ ์„œ๋น„์Šค ์šด์˜ ์ค‘์ด๋‹ค.


2. ๋„์ปค๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋Š” ์ด์œ 

2๋Œ€์˜ ์„œ๋ฒ„๊ฐ€ ์žˆ์„ ๋•Œ,

2๋Œ€์˜ ์„œ๋ฒ„ ์„ธํŒ… ์‹œ๊ธฐ๊ฐ€ ๋‹ค๋ฅด๋‹ค๋ฉด ,

์šด์˜์ฒด์ œ ๋ฒ„์ „๋ถ€ํ„ฐ ์ปดํŒŒ์ผ๋Ÿฌ, ์„ค์น˜๋œ ํŒจํ‚ค์ง€๊นŒ์ง€ ์™„๋ฒฝํ•˜๊ฒŒ ๊ฐ™๊ฒŒ ํ•˜๊ธฐ๊ฐ€ ์‰ฝ์ง€ ์•Š๋‹ค.


์ด๋Ÿฌํ•œ ์ฐจ์ด๋กœ ์ธํ•ด ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜๊ธฐ ์‰ฌ์šด๋ฐ,

๋„์ปค๋Š” ์„œ๋ฒ„๋งˆ๋‹ค ๋™์ผํ•œ ํ™˜๊ฒฝ์„ ๊ตฌ์„ฑํ•ด์ฃผ๊ธฐ ๋•Œ๋ฌธ์—

์ด๋Ÿฌํ•œ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค.


๋˜ํ•œ,
docker๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋™์ผํ•œ ํ™˜๊ฒฝ์„ ๊ตฌ์„ฑํ•˜๊ธฐ ๋•Œ๋ฌธ์— auto scaling์— ์œ ๋ฆฌํ•˜๋‹ค.



3. ๋„์ปค์™€ ๊ธฐ์กด ๊ฐ€์ƒํ™” ๊ธฐ์ˆ  (VM) ์˜ ์ฐจ์ด

Hypervisor

Hypervisor๋Š” (VM)

ํ˜ธ์ŠคํŠธ ์‹œ์Šคํ…œ (์œˆ๋„์šฐ, ๋ฆฌ๋ˆ…์Šค ๋“ฑ)์—์„œ

๋‹ค์ˆ˜์˜ ๊ฒŒ์ŠคํŠธ OS (๊ฐ€์ƒ๋จธ์‹ ) ๋ฅผ ๊ตฌ๋™ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•˜๋Š” ์†Œํ”„ํŠธ์›จ์–ด์ด๋‹ค.


๊ฐ VM ๋งˆ๋‹ค ๋…๋ฆฝ์ ์œผ๋กœ ๋™์ž‘ํ•œ๋‹ค.


Container

Container๋Š” (Docker)

ํ•˜์ดํผ ๋ฐ”์ด์ € ๊ตฌ์กฐ๋ฅผ ํ† ๋Œ€๋กœ ๋“ฑ์žฅํ–ˆ์œผ๋ฉฐ,

VM๋ณด๋‹ค ํ›จ์”ฌ ๊ฐ€๋ณ๊ฒŒ ๋™์ž‘ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์„ฑ๋Šฅ์— ์œ ๋ฆฌํ•˜๋‹ค.


Hypervisor ์™€ Containers ๋น„๊ต ์‚ฌ์ง„

์ถœ์ฒ˜ : https://www.virtasant.com/blog/hypervisors-a-comprehensive-guide



ใ€€

4. ๋„์ปค์˜ ์ด๋ฏธ์ง€์™€ ์ปจํ…Œ์ด๋„ˆ

  • ์ด๋ฏธ์ง€๋ž€
    ์ฝ”๋“œ, ๋Ÿฐํƒ€์ž„, ์‹œ์Šคํ…œ ๋„๊ตฌ, ์‹œ์Šคํ…œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋ฐ ์„ค์ •๊ณผ ๊ฐ™์€
    ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์„ ์‹คํ–‰ ํ•˜๋Š”๋ฐ ํ•„์š”ํ•œ ๋ชจ๋“  ๊ฒƒ์„ ํฌํ•จํ•˜๋Š” ํŒจํ‚ค์ง€์ด๋‹ค.

  • ์ด๋ฏธ์ง€๋Š” Github์™€ ์œ ์‚ฌํ•œ ์„œ๋น„์Šค์ธ https://hub.docker.com ์„ ํ†ตํ•ด ๋ฒ„์ „ ๊ด€๋ฆฌ๋œ๋‹ค.

  • ์ปจํ…Œ์ด๋„ˆ๋ž€

    • ๋„์ปค ์ด๋ฏธ์ง€๋ฅผ ๋…๋ฆฝ๋œ ๊ณต๊ฐ„์—์„œ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋Š” ๊ธฐ์ˆ ์ด๋‹ค.
    • ํ•˜๋‚˜์˜ ์ด๋ฏธ์ง€๋Š” ์—ฌ๋Ÿฌ๊ฐœ์˜ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค.
    • ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ด๋ฏธ์ง€ ์ธ์Šคํ„ด์Šค๋ผ๊ณ  ๋ถ€๋ฅด๊ธฐ๋„ ํ•œ๋‹ค.

ใ€€

5. ๋„์ปค ํŒŒ์ผ์ด๋ž€?

๋„์ปค ์ด๋ฏธ์ง€๋ฅผ ๊ตฌ์„ฑํ•˜๊ธฐ ์œ„ํ•ด ์žˆ์–ด์•ผํ• 

ํŒจํ‚ค์ง€, ์˜์กด์„ฑ, ์†Œ์Šค์ฝ”๋“œ ๋“ฑ์„ ํ•˜๋‚˜์˜ file๋กœ ๊ธฐ๋กํ•˜์—ฌ

์ด๋ฏธ์ง€ํ™” ์‹œํ‚ฌ ๋ช…๋ น ํŒŒ์ผ ์ด๋‹ค.


์ฆ‰,
์ด๋ฏธ์ง€๋Š” ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•œ ๋ชจ๋“  ์ •๋ณด๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์—,

๋” ์ด์ƒ ์ƒˆ๋กœ์šด ์„œ๋ฒ„๊ฐ€ ์ถ”๊ฐ€๋˜๋ฉด

์˜์กด์„ฑ ํŒŒ์ผ์„ ์ปดํŒŒ์ผํ•˜๊ณ  ์ด๊ฒƒ ์ €๊ฒƒ ์„ค์น˜ํ•  ํ•„์š”๊ฐ€ ์—†๋‹ค.



6. ๋„์ปค ํŒŒ์ผ ์ฃผ์š” ๋ช…๋ น์–ด

FROM

์ƒˆ๋กœ์šด ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•  ๋•Œ ๊ธฐ๋ฐ˜์œผ๋กœ ์‚ฌ์šฉํ•  ์ด๋ฏธ์ง€๋ฅผ ์ง€์ • ์ด๋ฏธ์ง€ ์ด๋ฆ„:ํƒœ๊ทธ

# ex. jdk 11 ์ด ์žˆ๋Š” ์ปจํ…Œ์ด๋„ˆ ์‚ฌ์šฉ
FROM openjdk:11

ARG

์ด๋ฏธ์ง€ ๋นŒ๋“œ ์‹œ์ ์—์„œ ์‚ฌ์šฉํ•  ๋ณ€์ˆ˜ ์ง€์ •

ARG JAR_FILE=build/libs/app.jar

COPY

ํ˜ธ์ŠคํŠธ์— ์žˆ๋Š” ํŒŒ์ผ์ด๋‚˜ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ Docker ์ด๋ฏธ์ง€์˜ ํŒŒ์ผ ์‹œ์Šคํ…œ์œผ๋กœ ๋ณต์‚ฌ

COPY ${JAR_FILE} ./app.jar

ENV

์ปจํ…Œ์ด๋„ˆ์—์„œ ์‚ฌ์šฉํ•  ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ์ง€์ •

# TimeZone ํ™˜๊ฒฝ ๋ณ€์ˆ˜
ENV TZ=Asia/Seoul

ENRTYPOINT

์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์‹คํ–‰๋˜์—ˆ์„ ๋•Œ ํ•ญ์ƒ ์‹คํ–‰๋˜์–ด์•ผ ํ•˜๋Š” ์ปค๋งจ๋“œ ์ง€์ •

ENRTYPOINT ["java", "-jar", "./app.jar"]

ใ€€

7. ๋„์ปค ์ปดํฌ์ฆˆ๋ž€?

  • Docker Compose๋ž€
    ๋ฉ€ํ‹ฐ ์ปจํ…Œ์ด๋„ˆ ๋„์ปค ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์ •์˜ํ•˜๊ณ  ์‹คํ–‰ํ•˜๋Š” ๋„๊ตฌ์ด๋‹ค.

  • Application , Database , Redis , Nginx ๋“ฑ
    ๊ฐ ๋…๋ฆฝ์ ์ธ ์ปจํ…Œ์ด๋„ˆ๋กœ ๊ด€๋ฆฌํ•œ๋‹ค๊ณ  ํ–ˆ์„ ๋•Œ
    ๋‹ค์ค‘ ์ปจํ…Œ์ด๋„ˆ ๋ผ์ดํ”„ ์‚ฌ์ดํด์„ ์–ด๋–ป๊ฒŒ ๊ด€๋ฆฌํ•ด์•ผ ํ• ๊นŒ?
    -> ๋„์ปค ์ปดํฌ์ฆˆ๋กœ ๊ด€๋ฆฌ!

  • ์—ฌ๋Ÿฌ๊ฐœ์˜ ๋„์ปค ์ปจํ…Œ์ด๋„ˆ๋กœ ๋ถ€ํ„ฐ ์ด๋ฃจ์–ด์ง„ ์„œ๋น„์Šค๋ฅผ ๊ตฌ์ถ• ,
    ๋„คํŠธ์›Œํฌ ์—ฐ๊ฒฐ , ์‹คํ–‰ ์ˆœ์„œ ๋ฅผ ์ž๋™์œผ๋กœ ๊ด€๋ฆฌ ํ•ด์ค€๋‹ค.

  • docker-compose.yml ํŒŒ์ผ์„ ์ž‘์„ฑํ•˜์—ฌ 1ํšŒ ์‹คํ–‰ํ•˜๋Š” ๊ฒƒ์œผ๋กœ
    ์„ค์ •๋œ ๋ชจ๋“  ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰.



ใ€€

8. Docker ์„ค์น˜

1. ๊ฐ OS์— ๋งž๊ฒŒ Docker ์„ค์น˜๋ฅผ ์ง„ํ–‰ํ•œ๋‹ค.

  • windows : https://docs.docker.com/desktop/install/windows-install/

    ๊ท€์—ฌ์šด๊ฒŒ ์ƒ๊ฒผ๋‹ผใ…‹ใ…‹

  • Linux Ubuntu

    • ubuntu 22.04์— docker ์„ค์น˜ : ubuntu ์„ค์น˜ ์ฐธ๊ณ  ๋งํฌ
      # ์šฐ๋ถ„ํˆฌ ์‹œ์Šคํ…œ ํŒจํ‚ค์ง€ ์—…๋ฐ์ดํŠธ
      sudo apt-get update
      # ํ•„์š”ํ•œ ํŒจํ‚ค์ง€ ์„ค์น˜
      sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
      # Docker์˜ ๊ณต์‹ GPGํ‚ค๋ฅผ ์ถ”๊ฐ€
      curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
      # Docker์˜ ๊ณต์‹ apt ์ €์žฅ์†Œ๋ฅผ ์ถ”๊ฐ€
      sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
      # ์‹œ์Šคํ…œ ํŒจํ‚ค์ง€ ์—…๋ฐ์ดํŠธ
      sudo apt-get update
      # Docker ์„ค์น˜
      sudo apt-get install docker-ce docker-ce-cli containerd.io
      # version ํ™•์ธ
      docker -v


2. hub.docker.com ๋ฌด๋ฃŒ ํ”Œ๋žœ ๊ฐ€์ž… ๋ฐ ๋กœ๊ทธ์ธ

https://hub.docker.com


3. docker compose ์„ค์น˜

docker compose ๋Š” Mac ๋˜๋Š” Windows ์˜ ๊ฒฝ์šฐ

Docker desktop ์„ ์„ค์น˜ํ•œ ๊ฒฝ์šฐ๋ผ๋ฉด

docker compose ์„ค์น˜๋ฅผ ์ง„ํ–‰ํ•  ํ•„์š”๊ฐ€ ์—†์œผ๋ฉฐ,

Linux์˜ ๊ฒฝ์šฐ ์ถ”๊ฐ€์ ์œผ๋กœ docker-compose ์„ค์น˜๊ฐ€ ํ•„์š”ํ•˜๋‹ค.

ubuntu 22.04์— docker compose ์„ค์น˜

# https://github.com/docker/compose/releases ์—์„œ ์ตœ์‹  ๋ฒ„์ „ ํ™•์ธํ›„ ์„ค์น˜
sudo curl -L "https://github.com/docker/compose/releases/download/v2.20.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# ์‹คํ–‰์ด ๊ฐ€๋Šฅํ•˜๊ฒŒ ๊ถŒํ•œ์„ ์„ธํŒ…
sudo chmod +x /usr/local/bin/docker-compose
# ์„ค์น˜ ๋ฒ„์ „ ํ™•์ธ
sudo docker-compose -v


9. Docker ๋กœ๊ทธ์ธ

windows์˜ ๊ฒฝ์šฐ power shell์„ ์‹คํ–‰ํ•˜๊ณ  ์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•œ๋‹ค.

ubuntu์—์„  shell์— ๋ฐ”๋กœ ์ž…๋ ฅ

docker login

windows

๋กœ๊ทธ์ธ ์‹คํŒจ์‹œ ์ขŒ์ธก ํ•˜๋‹จ์— ๋„์ปค ๋ฐ์Šคํฌํƒ‘์ด ์‹คํ–‰์ค‘์ธ์ง€ ํ™•์ธ!


ubuntu


ใ€€

10. ๋‹จ์ผ ์ปจํ…Œ์ด๋„ˆ ํ™˜๊ฒฝ ์‹ค์Šต

๋ชฉํ‘œ : Spring Boot ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ด๋ฏธ์ง€ํ™” ํ›„ ์ปจํ…Œ์ด๋„ˆ์—์„œ ์‹คํ–‰


10-1. jar ํŒŒ์ผ ์ƒ์„ฑ

์ธํ…”๋ฆฌ์ œ์ด ๋‚ด์žฅ terminal์„ ์‚ฌ์šฉํ•˜๋ฉด

ํ”„๋กœ์ ํŠธ ํ˜„์žฌ ์œ„์น˜์—์„œ ์‹คํ–‰๋˜์–ด ํŽธํ•˜๋‹ค.


์ธํ…”๋ฆฌ์ œ์ด๋กœ ํ”„๋กœ์ ํŠธ ์‹คํ–‰ ํ›„ ๋‚ด์žฅ ํ„ฐ๋ฏธ๋„ ์—ด๊ธฐ.


10-1-1. ์ƒ์„ฑ๋  jar ํŒŒ์ผ ์ด๋ฆ„ ์„ค์ •

jar ํŒŒ์ผ ์ด๋ฆ„์„ app.jar๋กœ ์ง€์ •ํ•ด์„œ ์ƒ์„ฑ๋˜๋„๋ก ํ•˜๊ณ ์ž ํ•œ๋‹ค.

build.gradle ํŒŒ์ผ์„ ์‹คํ–‰ ํ›„ ๋‹ค์Œ์˜ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด์ค€๋‹ค.

bootJar {
    archiveFileName = 'app.jar'
}

10-1-2. build !

(windows)

.\gradlew clean
.\gradlew build


10-2. docker file ์ž‘์„ฑ

10-2-1. ํ”„๋กœ์ ํŠธ์˜ ๋ฃจํŠธ ๋””๋ ‰ํ† ๋ฆฌ์— ํŒŒ์ผ ์ƒ์„ฑ

ํŒŒ์ผ ์ด๋ฆ„ : Dockerfile


10-2-2. ํŒŒ์ผ ๋‚ด์šฉ ์ž‘์„ฑ

#Dockerfile

FROM openjdk:11
ARG JAR_FILE=build/libs/app.jar
COPY ${JAR_FILE} ./app.jar
ENV TZ=Asia/Seoul
ENTRYPOINT ["java", "-jar", "./app.jar"]

10-2-3. docker file build

docker build -t {docker hub username}/{file name} {docker file ์œ„์น˜}

docker build -t zhyun/jar-docker-file-test .


์ƒ์„ฑ๋œ docker images ํ™•์ธ!

docker images


10-3. docker ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰

docker run ๋ช…๋ น์–ด ์‚ฌ์šฉ!

docker run zhyun/jar-docker-file-test -p 8080:8080

-p : {host port}:{์ปจํ…Œ์ด๋„ˆ port}


docker ๊ฐ€ ์ •์ƒ ๋™์ž‘์ค‘์ธ์ง€ ํ™•์ธ์„ ์œ„ํ•ด terminal์„ ํ•˜๋‚˜ ์ƒˆ๋กœ ์—ด๊ณ 

์•„๋ž˜์™€ ๊ฐ™์ด ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•œ๋‹ค.

docker ps

์‹คํ–‰์ค‘์ธ docker images ํ™•์ธ ๊ฐ€๋Šฅ!


+ ์‹คํ–‰์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ์— ๋“ค์–ด๊ฐ€๋ณด๊ธฐ

docker exec -it {container id} {shell}

docker exec -it 4d10189fd2a5 bash


์šฐ์™€ ๐Ÿ˜€

ใ€€

11. ๋‹ค์ค‘ ์ปจํ…Œ์ด๋„ˆ ํ™˜๊ฒฝ ์‹ค์Šต

11-1. ๋„์ปค ์ปดํฌ์ฆˆ ํŒŒ์ผ์— ์ž‘์„ฑํ•ด์•ผ ํ•  ์ •๋ณด : docker-compose.yml

version

๋„์ปค ์—”์ง„๋ฒ„์ „์— ๋”ฐ๋ฅธ ์ปดํฌ์ฆˆ ๋ฒ„์ „ ์„ ํƒ
compose-v3
compose-v2

service

์ด๊ณณ์— ์‹คํ–‰ํ•˜๋ ค๋Š” ์ปจํ…Œ์ด๋„ˆ๋“ค์„ ์ •์˜

pharmacy-recommendation-app

์„œ๋น„์Šค๋ช… ( ๋„คํŠธ์›Œํฌ ํ˜ธ์ŠคํŠธ๋ช… ) / ๊ฐ™์€ ๋„คํŠธ์›Œํฌ์— ์†ํ•œ ์ปจํ…Œ์ด๋„ˆ๋ผ๋ฆฌ ์„œ๋น„์Šค ๋ช…์œผ๋กœ ์ ‘๊ทผ
๊ฐ€๋Šฅ

container_name

์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„

build

dockerfile ์ด ์žˆ๋Š” ์œ„์น˜

depends_on

ํŠน์ • ์ปจํ…Œ์ด๋„ˆ์— ๋Œ€ํ•œ ์˜์กด๊ด€๊ณ„

image

์ปจํ…Œ์ด๋„ˆ ์ƒ์„ฑํ•  ๋•Œ, ์‚ฌ์šฉํ•  ๋„์ปค ์ด๋ฏธ์ง€ ์ง€์ •

environment

ํ™˜๊ฒฝ ๋ณ€์ˆ˜

volumnes

ํ˜ธ์ŠคํŠธ ๋””๋ ‰ํ† ๋ฆฌ : ์ปจํ…Œ์ด๋„ˆ ๋””๋ ‰ํ† ๋ฆฌ

ports

์ ‘๊ทผ ํฌํŠธ ์„ค์ • (์ปจํ…Œ์ด๋„ˆ ์™ธ๋ถ€ : ์ปจํ…Œ์ด๋„ˆ ๋‚ด๋ถ€)
--> docker run -p ์˜ต์…˜๊ณผ ๊ฐ™์œผ๋ฉฐ, ๊ฐœ๋ฐฉํ•  ํฌํŠธ๋ฅผ ์ง€์ •ํ•˜๋Š” ๊ฒƒ

restart

์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰ ์‹คํŒจํ•˜๋Š” ๊ฒฝ์šฐ ์žฌ์‹œ์ž‘ ์—ฌ๋ถ€




11-2. ์‹ค์Šต : ๋กœ์ปฌ์—์„œ mariadb , redis ์ปจํ…Œ์ด๋„ˆ ๋„์›Œ์„œ ์‚ฌ์šฉ

11-2-1. Dockerfile ์ž‘์„ฑ

mariadb

# /database/Dockerfile

FROM mariadb:10

ENV TZ=Asia/Seoul

redis

# /redis/Dockerfile

FROM redis:6

ENV TZ=Asia/Seoul

11-2-2. ๋„์ปค ์ปดํฌ์ฆˆ ํŒŒ์ผ ์ž‘์„ฑ

version: "3.8"

services:
  
  jar-docker-file-test-maria:
    container_name: /jar-docker-file-test-maria
    build:
      dockerfile: Dockerfile
      context: ./database
    image: zhyun/jar-docker-file-test-maria
    environment:
      - MARIADB_DATABASE=fc-pharmacy-directions
      - MARIADB_ROOT_PASSWORD=${SPRING_DATASOURCE_PASSWORD}
    volumes:
      - ./database/config:/etc/mysql/conf.d
    ports:
      - "3303:3306"  # localhost์—์„œ 3306 port ๋ฅผ ์‚ฌ์šฉ์ค‘์ด๊ธฐ ๋•Œ๋ฌธ์— 3303์œผ๋กœ ์ ‘๊ทผ

  jar-docker-file-test-redis:
    container_name: /jar-docker-file-test-redis
    build:
      dockerfile: Dockerfile
      context: ./redis
    image: zhyun/jar-docker-file-test-redis
    ports:
      - "6379:6379"

11-2-3. docker-compose ๋ช…๋ น์–ด๋กœ ์ปจํ…Œ์ด๋„ˆ ๋„์šฐ๊ธฐ

docker-compose -f docker-compose-local.yml up

์ปจํ…Œ์ด๋„ˆ ๋™์ž‘ ํ™•์ธ

docker ps


11-2-4. spring boot application.yml ์—์„œ ์ ‘์† ์ •๋ณด ์„ค์ • ํ›„ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹คํ–‰

# ์‹คํ–‰ ํ•  ํ™˜๊ฒฝ ์ •๋ณด ์ž‘์„ฑ

spring:
  profiles:
    active: local
    group:
      local:
        - common
      prod:
        - common

---

# profile ์„ค์ • 1 : common

spring:
  config:
    activate:
      on-profile: common

---

# profile ์„ค์ • 2 : local

spring:
  config:
    activate:
      on-profile: local
  datasource:
    driver-class-name: org.mariadb.jdbc.Driver
    url: jdbc:mariadb://localhost:3303/fc-pharmacy-directions
    username: ${SPRING_DATASOURCE_USERNAME}
    password: ${SPRING_DATASOURCE_PASSWORD}

  redis:
    host: localhost
    port: 6379

  jpa:
    hibernate:
      ddl-auto: create
    show-sql: true

---

# profile ์„ค์ • 3 : prod

spring:
  config:
    activate:
      on-profile: prod

post-custom-banner

1๊ฐœ์˜ ๋Œ“๊ธ€

comment-user-thumbnail
2023๋…„ 7์›” 22์ผ

๊ธ€ ์ž˜ ๋ดค์Šต๋‹ˆ๋‹ค.

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ