[Docker] Dockerfile

Hyunhoยท2022๋…„ 8์›” 14์ผ
0

๐Ÿ“์ •๋ฆฌ

Docker๋ฅผ ์ด์šฉํ•ด jarํŒŒ์ผ์„ ๋ฐฐํฌํ•˜๋ฉด์„œ ํ”„๋กœ์ ํŠธ์— ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์„ค์ •์„ ํ•˜๋Š” ๋ถ€๋ถ„์ด ์žˆ์–ด Dockerfile์— ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋ฅผ ์ถ”๊ฐ€ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ์ถ”๊ฐ€๋ฅผ ์œ„ํ•ด Dockerfile์— ๋Œ€ํ•œ ์กฐ์‚ฌ๋ฅผ ํ•˜๋ฉด์„œ ํ•™์Šตํ•œ ๋‚ด์šฉ์„ ์ •๋ฆฌํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

1.Dockerfile ์†Œ๊ฐœ

Dockerfile์€ DockerImage๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•œ ์„ค์ • ํŒŒ์ผ์ž…๋‹ˆ๋‹ค.
(Dockerfile์„ ๋นŒ๋“œํ•˜๋ฉด Docker Image๋ฅผ ์ƒ์„ฑํ•ด์ค€๋‹ค)
Dockerfile์˜ ์žฅ์ ์€ ์ด๋ฏธ์ง€๊ฐ€ ์–ด๋–ป๊ฒŒ ๋งŒ๋“ค์–ด์กŒ๋Š์ง€๋ฅผ ๊ธฐ๋กํ•˜๋ฉฐ, ๋ฐฐํฌ์ด ์šฉ์ดํ•˜๊ณ  ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ํŠน์ • ํ–‰๋™์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ค๋‹ˆ๋‹ค.

2. Dockerfile ๊ตฌ์„ฑ

FROM openjdk:11-jdk
EXPOSE 80
ARG JAR_FILE=target/*.jar
ADD ${JAR_FILE} api.jar
ENV JASYPT_SECRET="value"
WORKDIR /home/api
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/api.jar"]
  • FROM - Base ์ด๋ฏธ์ง€
    • FROM <์ด๋ฏธ์ง€>
  • EXPOSE - ์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€์—์„œ ์—ด์–ด์ค„ ํฌํŠธ๋ฒˆํ˜ธ
    • EXPOSE <ํฌํŠธ๋ฒˆํ˜ธ>
    • ์ปจํ…Œ์ด๋„ˆ ์ƒ์„ฑ์‹œ -p์˜ต์…˜์˜ ์ปจํ…Œ์ด๋„ˆ ํฌํŠธ ๊ฐ’์œผ๋กœ EXPOSE์— ์ž‘์„ฑํ•œ ๊ฐ’์„ ์ ์–ด์•ผ ํ•œ๋‹ค.
  • ADD - build ๋ช…๋ น ์ค‘๊ฐ„์— ํ˜ธ์ŠคํŠธ์˜ ํŒŒ์ผ ๋˜๋Š” ํด๋”๋ฅผ ์ด๋ฏธ์ง€์— ๊ฐ€์ ธ์˜จ๋‹ค
  • ARG - docker build๋กœ ์ด๋ฏธ์ง€๋ฅผ ๋นŒ๋“œ ์‹œ ์˜ต์…˜์„ ํ†ตํ•ด ๋„˜๊ธธ ์ˆ˜ ์žˆ๋Š” ์ธ์ž๋ฅผ ์ •์˜
    • ARG <์ด๋ฆ„>
  • ENV - ์ด๋ฏธ์ง€์—์„œ ์‚ฌ์šฉํ•  ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ๊ฐ’์„ ์ €์žฅ
    • ENV <KEY> <VALUE>
  • WORKDIR - ์ปจํ…Œ์ด๋„ˆ ์ƒ์—์„œ ์ž‘์—… ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ง€์ •
    • WORKDIR <์ด๋™ํ•  ๊ฒฝ๋กœ>
    • ํ•ด๋‹น ๋””๋ ‰ํ† ๋ฆฌ๊ฐ€ ์—†์œผ๋ฉด ์ƒˆ๋กœ ์ƒ์„ฑ
    • RUN,CMD,ENTRYPOINT,COPY,ADD ๋ช…๋ น๋ฌธ์€ ํ•ด๋‹น ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์‹ฑํ–‰
  • ENTRYPOINT - docker run ์‹คํ–‰ ์‹œ ํ•ญ์ƒ ์‹คํ–‰๋˜์•ผ ํ•˜๋Š” ์ปค๋งจ๋“œ๋ฅผ ์ง€์ •ํ•  ๋•Œ ์‚ฌ์šฉ
    • ENTRYPOINT ["์ปค๋งจ๋“œ","ํŒŒ๋ผ๋ฏธํ„ฐ1","ํŒŒ๋ผ๋ฏธํ„ฐ2"]
    • Docker Image๋ฅผ ํ•˜๋‚˜์˜ ์‹คํ–‰ ํŒŒ์ผ์ฒ˜๋Ÿผ ์‚ฌ์šฉ

์ฐธ๊ณ 

๐Ÿ’ก https://freedeveloper.tistory.com/188

profile
hyunho

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