"Docker์ ๊ธฐ๋ณธ ๊ฐ๋ ๊ณผ ์ปจํ ์ด๋ํ์ ์ฅ์ ์ ๋ํด ์ค๋ช ํด์ฃผ์ธ์. ๊ฐ์ํ(VM)์ ์ปจํ ์ด๋์ ์ฐจ์ด์ ์ ๋ฌด์์ธ๊ฐ์?"
[๊ธฐ์กด ๊ฐ์ํ] [Docker ์ปจํ
์ด๋]
+----------------+ +----------------+
| App A | App B | | App A | App B |
+----------------+ +----------------+
| Guest OS A|B | | Container A|B |
+----------------+ +----------------+
| Hypervisor | | Docker Engine |
+----------------+ +----------------+
| Host OS | | Host OS |
+----------------+ +----------------+
| Infrastructure | | Infrastructure |
+----------------+ +----------------+
# Dockerfile ์์
FROM openjdk:11-jdk
WORKDIR /app
COPY target/myapp.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","app.jar"]
# Docker Image ๋น๋
docker build -t myapp:1.0 .
# Docker Container ์คํ
docker run -d -p 8080:8080 myapp:1.0
# ์ด๋ฏธ์ง ์กฐํ
docker images
# ์ด๋ฏธ์ง ํ
docker pull nginx:latest
# ์ด๋ฏธ์ง ์ญ์
docker rmi nginx:latest
# ์ด๋ฏธ์ง ๋น๋
docker build -t myapp:latest .
# ์ปจํ
์ด๋ ์คํ
docker run -d --name mycontainer -p 8080:8080 myapp:latest
# ์ปจํ
์ด๋ ๋ชฉ๋ก ์กฐํ
docker ps
docker ps -a # ์ค์ง๋ ์ปจํ
์ด๋ ํฌํจ
# ์ปจํ
์ด๋ ์ค์ง/์์
docker stop mycontainer
docker start mycontainer
# ์ปจํ
์ด๋ ๋ก๊ทธ ํ์ธ
docker logs mycontainer
docker logs -f mycontainer # ์ค์๊ฐ ๋ก๊ทธ
# Multi-stage build ์์
FROM maven:3.8.4-openjdk-11 AS build
WORKDIR /app
COPY pom.xml .
COPY src ./src
RUN mvn clean package -DskipTests
FROM openjdk:11-jre-slim
COPY --from=build /app/target/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","app.jar"]
FROM node:14-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
# docker-compose.yml
version: '3'
services:
app:
build: .
ports:
- "8080:8080"
environment:
- SPRING_PROFILES_ACTIVE=prod
- DB_HOST=db
depends_on:
- db
db:
image: mysql:8.0
environment:
- MYSQL_ROOT_PASSWORD=rootpass
- MYSQL_DATABASE=myapp
volumes:
- db-data:/var/lib/mysql
volumes:
db-data:
-
"Docker ์ปจํ ์ด๋์ ๋ก๊ทธ ๊ด๋ฆฌ๋ ์ด๋ป๊ฒ ํ์๋์?"
-
"์ปจํ ์ด๋ ๋ชจ๋ํฐ๋ง์ ์ด๋ค ๋๊ตฌ๋ฅผ ์ฌ์ฉํ์๋์?"
-
"Docker ์ด๋ฏธ์ง ํฌ๊ธฐ๋ฅผ ์ต์ ํํ๋ ๋ฐฉ๋ฒ์ ๋ฌด์์ธ๊ฐ์?"
-
"Docker ๋ณด์์ ์ํด ์ด๋ค ์กฐ์น๋ค์ ์ทจํ์๋์?"
docker run -d \
--name myapp \
--memory="512m" \
--cpus="1.0" \
-p 8080:8080 \
myapp:latest
HEALTHCHECK --interval=30s --timeout=3s \
CMD wget --quiet --tries=1 --spider http://localhost:8080/health || exit 1
# JSON ๋ก๊ทธ ๋๋ผ์ด๋ฒ ์ฌ์ฉ
docker run -d \
--log-driver json-file \
--log-opt max-size=10m \
--log-opt max-file=3 \
myapp:latest
์ค์ ๋ฉด์ ์์๋ ์ด๋ก ์ ์ธ ์ง์๊ณผ ํจ๊ป Docker๋ฅผ ์ค์ ํ๋ก์ ํธ์์ ์ด๋ป๊ฒ ํ์ฉํ๋์ง, ๋ฐ์ํ ๋ฌธ์ ๋ค์ ์ด๋ป๊ฒ ํด๊ฒฐํ๋์ง ๊ตฌ์ฒด์ ์ธ ๊ฒฝํ์ ๊ณต์ ํ๋ ๊ฒ์ด ์ข์ต๋๋ค.