-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca50fa5
commit 7a891fe
Showing
11 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
## ์์ฝ | ||
์ค๋๋ ๋ง์ ๊ธฐ์ ์ด ์ ํ์ ๋ฐฐํฌํ ๋ ์ปจํ ์ด๋ ํ๊ฒฝ์ ์ฌ์ฉํ๋ค. ๋ ๋ง์ ์๋น์ค๋ฅผ ๊ฐ๋ฐํจ์ ๋ฐ๋ผ, ์ด๋ฅผ ์ ๊ณตํ๊ธฐ ์ํด ๋ ๋ง์ ์๋ฒ๊ฐ ํ์ํ๊ฒ ๋๋ฉฐ, ์ด๋ ๋ง์ดํฌ๋ก์๋น์ค ์ํคํ ์ฒ(MSA)๋ฅผ ์ฑํํ๊ฒ ๋ง๋ ๋ค. ๋์์ ์ปจํ ์ด๋ ์ฌ์ฉ์ด ์ฆ๊ฐํจ์ ๋ฐ๋ผ Docker ์ด๋ฏธ์ง๋ฅผ ํจ์จ์ ์ผ๋ก ๊ด๋ฆฌํ๋ ๊ฒ์ด ์ปจํ ์ด๋ ๊ธฐ๋ฐ ์ธํ๋ผ๋ฅผ ์ ์งํ๋ ๋ฐ ์ค์ํ๋ค. ๋ณธ ๊ธ์์๋ Docker ์ด๋ฏธ์ง์ ๋ณด์์ฑ๊ณผ ์ฑ๋ฅ์ ๊ฐ์ ํ๋ ๋ฐฉ๋ฒ์ ์ค๋ช ํ๋ค. | ||
|
||
--- | ||
|
||
### Docker ์ด๋ฏธ์ง ์ทจ์ฝ์ ํด๊ฒฐ | ||
Docker ์ด๋ฏธ์ง๋ ๊ณต์์ ์ผ๋ก ์ธ์ฆ๋ ์ด๋ฏธ์ง๋ผ ํ๋๋ผ๋ ์ทจ์ฝ์ ์ ๊ฐ์ง ์ ์๋ค. ์ด๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด ์ทจ์ฝ์ ์ด ์๋ ์ด๋ฏธ์ง๋ฅผ ์ฌ์ฉํ๊ฑฐ๋, ๋ฒ์ ์ ์ ๋ฐ์ดํธํ๊ฑฐ๋, ๋ฒ ์ด์ค ์ด๋ฏธ์ง๋ฅผ ๋ณ๊ฒฝํ ์ ์๋ค. | ||
|
||
```dockerfile | ||
FROM openjdk:17 | ||
|
||
EXPOSE 8080 | ||
|
||
COPY /font/NanumGothic.ttf /font/NanumGothic.ttf | ||
COPY /hospital/hospital-application/build/libs/hospital-application-0.0.1-SNAPSHOT.jar /app.jar | ||
|
||
ENV JAVA_TOOL_OPTIONS -Djava.security.properties=/java/security/enableLegacyTLS.security -Dfile.encoding=UTF8 | ||
ENV MODULE_NAME hospital | ||
ENV TZ Asia/Seoul | ||
|
||
ENTRYPOINT ["java", "-Dspring.profiles.active=develop", "-jar", "/app.jar"] | ||
``` | ||
|
||
์ ์์๋ ์ด๊ธฐ ์ ํ๋ฆฌ์ผ์ด์ ์์ ์ฌ์ฉํ๋ OpenJDK 17 ๋ฒ ์ด์ค ์ด๋ฏธ์ง๋ฅผ ๋ณด์ฌ์ค๋ค. ํด๋น ์ด๋ฏธ์ง๋ ์ง์์ด ์ข ๋ฃ๋์๊ณ ์ฌ๋ฌ ์ทจ์ฝ์ ์ ํฌํจํ๊ณ ์์๋ค. | ||
<img src="./image/Pasted image 20240719110709.png"> | ||
๊ทธ๋์ ๋ฒ ์ด์ค ์ด๋ฏธ์ง๋ฅผ `amazoncorretto:17`๋ก ๋ณ๊ฒฝํ๋ค. | ||
<img src="./image/Pasted image 20240719110721.png"> | ||
๊ทธ๋ฌ๋ `amazoncorretto:17`๋ก ๋ณ๊ฒฝํ ํ์๋ ๋คํธ์ํฌ ๋ณด์๊ณผ ๊ด๋ จ๋ ์ทจ์ฝ์ ์ด ์ฌ์ ํ ๋จ์ ์์๋ค. ์ด์ ๋ฐ๋ผ `amazonlinux:2023`์ ๊ธฐ๋ฐ์ผ๋ก ํ `amazoncorretto:17.0.10-al2023` ์ด๋ฏธ์ง๋ฅผ ์ฌ์ฉํ๋ค([Docker](https://hub.docker.com/layers/library/amazoncorretto/17.0.10-al2023/images/sha256-788e2e45f885e4ddeb881d5616e8b6976898c475ae3311e65263f64ec46f103c?context=explore)). | ||
<img src="./image/Pasted image 20240719110733.png"> | ||
๋ํ [Ubuntu Packages Search](https://packages.ubuntu.com/) ์ฌ์ดํธ์์ OS ์ด๋ฏธ์ง์ ์ ๋ณด์ ์ทจ์ฝ์ ์ ๊ฒ์ํ ์ ์๋ค. | ||
<img src="./image/Pasted image 20240719142307.png"> | ||
|
||
--- | ||
|
||
### ๊ฒฝ๋ Docker ์ด๋ฏธ์ง | ||
<img src="./image/Pasted image 20240719110958.png"> | ||
Docker ์ด๋ฏธ์ง ํฌ๊ธฐ๋ฅผ ์ค์ด๋ ๊ฒ์ Docker ์ปจํ ์ด๋๋ฅผ ํจ์จ์ ์ผ๋ก ๋ฐฐํฌํ๊ธฐ ์ํด ์ค์ํ๋ค. Docker ์ด๋ฏธ์ง ํฌ๊ธฐ๊ฐ ํฌ๋ฉด ๋ค์๊ณผ ๊ฐ์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ๋ค: | ||
- ์ด๋ฏธ์ง ๋น๋ ์๊ฐ์ด ์ฆ๊ฐํ๋ค. | ||
- ์ด๋ฏธ์ง๋ฅผ ๋ ์ง์คํธ๋ฆฌ์ ํธ์ํ๋ ์๊ฐ์ด ์ฆ๊ฐํ๋ค. | ||
- ๋ ์ง์คํธ๋ฆฌ์์ ์ด๋ฏธ์ง๋ฅผ ํ๋งํ๋ ์๊ฐ์ด ์ฆ๊ฐํ๋ค. | ||
|
||
์ด๋ฌํ ๋ฌธ์ ๋ CI/CD ํ๋ก์ธ์ค์ ์ค์ผ์ผ ์์ ์๊ฐ์ ์ฆ๊ฐ์ํค๋ฉฐ, ์๋ฒ ์คํ ๋ฆฌ์ง๋ฅผ ๋ญ๋นํ๊ฒ ๋ง๋ ๋ค. Docker ์ด๋ฏธ์ง ํฌ๊ธฐ๋ฅผ ์ค์ด๋ ๋ ๊ฐ์ง ๋ฐฉ๋ฒ์ ์๊ฐํ๋ค. | ||
|
||
#### Distroless ์ฌ์ฉ | ||
์ฒซ ๋ฒ์งธ ๋ฐฉ๋ฒ์ Distroless ์ด๋ฏธ์ง๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด๋ค. Google์ด ๊ฐ๋ฐํ Distroless ์ด๋ฏธ์ง๋ ๊ฐ์ฅ ์์ ํฌ๊ธฐ์ ์ด๋ฏธ์ง ์ค ํ๋๋ค. Distroless ์ด๋ฏธ์ง๋ ์ ํ๋ฆฌ์ผ์ด์ ๊ณผ ์คํ์ ํ์ํ ๋ฐํ์ ์ข ์์ฑ๋ง ํฌํจํ๋ค. | ||
์๋ฅผ ๋ค์ด, ๊ฐ์ฅ ์์ Distroless ์ด๋ฏธ์ง์ธ `gcr.io/distroless/static-debian11`๋ ์ฝ 2 MiB ํฌ๊ธฐ์ด๋ฉฐ, ์ด๋ `alpine`(~5 MiB)์ ์ฝ 50%์ด๊ณ , `debian`(124 MiB)์ 2% ๋ฏธ๋ง์ด๋ค. ์๋๋ Distroless ์ด๋ฏธ์ง๋ฅผ ์ฌ์ฉํ๋ ์์ ๋ค. | ||
|
||
```dockerfile | ||
# ์ ํ๋ฆฌ์ผ์ด์ ๋น๋ | ||
FROM golang:1.18 as build | ||
|
||
WORKDIR /go/src/app | ||
COPY . . | ||
|
||
RUN go mod download | ||
RUN CGO_ENABLED=0 go build -o /go/bin/app | ||
|
||
# ๋น๋๋ ์ ํ๋ฆฌ์ผ์ด์ ์ Distroless ์ด๋ฏธ์ง์ ๋ณต์ฌ | ||
FROM gcr.io/distroless/static-debian11 | ||
COPY --from=build /go/bin/app / | ||
CMD ["/app"] | ||
``` | ||
|
||
Distroless ์ด๋ฏธ์ง์ ๊ด๋ จ๋ ๋ค์ํ ์ด๋ฏธ์ง๋ [GitHub ๋งํฌ](https://github.com/GoogleContainerTools/distroless)์์ ํ์ธํ ์ ์๋ค. Distroless ์ด๋ฏธ์ง๋ฅผ ์ ํ๋ฆฌ์ผ์ด์ ์ด๋ฏธ์ง๋ก ์ฌ์ฉํ๋ฉด ์ฑ๋ฅ์ ํฌ๊ฒ ๊ฐ์ ํ ์ ์๋ค. | ||
|
||
#### ๋ ์ด์ด ์ต์ํ | ||
Docker ๋ช ๋ น์ด(์: `RUN`)๋ ์ฌ์ฉ ์๋ง๋ค ๋ ์ด์ด๋ฅผ ์์ฑํ๋ค. ๋ฐ๋ผ์ ์ฌ๋ฌ ๋ช ๋ น์ด๋ฅผ ํ ๋ฒ์ ์คํํ๋๋ก `RUN` ๋ช ๋ น์ด๋ฅผ ๋ณ๊ฒฝํ ์ ์๋ค. | ||
|
||
```dockerfile | ||
FROM alpine:3.14 | ||
LABEL maintainer="FastCampus Park <fastcampus@fastcampus.com>" | ||
LABEL description="Simple utility to send slack message easily." | ||
|
||
# ํ์ํ ํจํค์ง ์ค์น | ||
RUN \ | ||
apk add --no-cache bash curl git && \ | ||
git clone https://github.com/course-hero/slacktee /slacktee && \ | ||
apk del --no-cache git | ||
RUN chmod 755 /slacktee/slacktee.sh | ||
|
||
# ์คํ | ||
WORKDIR /slacktee | ||
ENTRYPOINT ["/bin/bash", "-c", "./slacktee.sh"] | ||
``` | ||
|
||
`&&` ๊ตฌ๋ฌธ์ ์ฌ์ฉํ์ฌ ์ฌ๋ฌ ๋ช ๋ น์ด๋ฅผ ๊ฒฐํฉํ ์ ์๋ค. ๋ํ `--no-cache` ์ต์ ์ ์ฌ์ฉํ๋ฉด ์ด๋ฏธ์ง ๋น๋ ๊ณผ์ ์์ ๋ถํ์ํ ์บ์ ๋ฐ์ดํฐ๋ฅผ ์ ๊ฑฐํ ์ ์๋ค. | ||
|
||
--- | ||
|
||
#### Docker ๋ฉํฐ ์คํ ์ด์ง ๋น๋ | ||
<img src="./image/Pasted image 20240719110933.png"> | ||
Docker ๋ฉํฐ ์คํ ์ด์ง ๋น๋๋ฅผ ์ฌ์ฉํ๋ฉด Dockerfile์์ ์ฌ๋ฌ ๋จ๊ณ๋ฅผ ์ ์ํ ์ ์๋ค. ์ด๋ฅผ ํตํด ํ์ํ ๊ตฌ์ฑ ์์๋ง ํฌํจ๋ ์ต์ํ์ ์ต์ข ์ด๋ฏธ์ง๋ฅผ ์์ฑํ ์ ์๋ค. | ||
์๋๋ Spring Boot ์ ํ๋ฆฌ์ผ์ด์ ์ ์ํ ๋ฉํฐ ์คํ ์ด์ง ๋น๋์ ์์ ๋ค. | ||
|
||
```dockerfile | ||
FROM amazoncorretto:17.0.10-al2023 AS base | ||
WORKDIR /app | ||
COPY /docker/docker-application/build/libs/docker-application-0.0.1-SNAPSHOT.jar /app.jar | ||
RUN java -Djarmode=layertools -jar app.jar extract | ||
|
||
FROM amazoncorretto:17.0.10-al2023 | ||
WORKDIR /app | ||
EXPOSE 8080 | ||
COPY --from=base /app/dependencies/ ./ | ||
COPY --from=base /app/spring-boot-loader/ ./ | ||
COPY --from=base /app/snapshot-dependencies/ ./ | ||
COPY --from=base /app/application/ ./ | ||
ENV MODULE_NAME docker | ||
ENV TZ Asia/Seoul | ||
|
||
ENTRYPOINT ["java", "-Dspring.profiles.active=develop", "org.springframework.boot.loader.JarLauncher"] | ||
``` | ||
|
||
์ Dockerfile์ ๋น๋ ๋จ๊ณ์์ JAR ํ์ผ์ ์ถ์ถํ๊ณ ์ด๋ฅผ ์ฌ๋ฌ ๋ ์ด์ด๋ก ๋๋๋ค. ์คํ ๋จ๊ณ์์๋ ํ์ํ ๋ชจ๋ ์ข ์์ฑ์ ๋ฒ ์ด์ค ์ด๋ฏธ์ง์์ ๊ฐ์ ธ์ `JarLauncher`๋ฅผ ์ฌ์ฉํด ์ ํ๋ฆฌ์ผ์ด์ ์ ์คํํ๋ค. ์ด ๋ฐฉ์์ JAR ํ์ผ์ ์์ถ ํด์ ์์ ์ ์๋ตํ์ฌ ํจ์จ์ฑ์ ๋์ด๋ฉฐ, ์ ํ๋ฆฌ์ผ์ด์ ์ ๋ ์ด์ด๋ฅผ ์บ์ฑํ์ฌ ๋น๋ ์๋๋ฅผ ๊ฐ์ ํ๋ค. | ||
|
||
--- | ||
|
||
### ๊ฒฐ๋ก | ||
<img src="./image/Pasted image 20231113162741.png"> | ||
๋ณธ ๊ธ์์๋ Docker ์ด๋ฏธ์ง๋ฅผ ํจ์จ์ ์ผ๋ก ๊ด๋ฆฌํ๋ ๋ฐฉ๋ฒ์ ๋ํด ๋ ผ์ํ๋ค. ์ปจํ ์ด๋ ๊ธฐ๋ฐ ๋ฐฐํฌ๋ ํ๋ ๋ฐฑ์๋ ์์คํ ์์ ์ง๋ฐฐ์ ์ธ ์ํคํ ์ฒ๋ค. ๋ณด์ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ณ Docker ์ด๋ฏธ์ง ํฌ๊ธฐ๋ฅผ ์ค์ด๋ ๊ฒ์ ์ธํ๋ผ๋ฅผ ์ ์งํ๊ณ ์๋น์ค๋ฅผ ์ด์ํ๋ ๋ฐ ๋งค์ฐ ์ค์ํ๋ค. |