๐ก Lightweight Dockerfile for CI/CD Pipeline โ Executive Summary
Technical architectural analysis, practical configuration manifests, and deployment instructions for Lightweight Dockerfile for CI/CD Pipeline.
Command
bash
# Dockerfile ๊ฒฝ๋ก์์
docker build -t ${registry}/${image}:${tag} .
Configuration
COPY
References and Guidelines (NOTE)
The last argument value of COPY is Destination Directory.
Everything before it is Source.
docker
COPY <Source 1> <Source 2> <Source 3> ... <Destination>
RUN, CMD, ENTRYPOINT
| command | When to run | purpose | Is it possible to overwrite? |
| RUN | ๐๏ธ When building images | Run commands to configure the image (install files, build, etc.) | โ (Results are reflected in the image) |
| CMD | ๐ When running container | Dynamic argument value of dynamic execution command or ENTRYPOINT |
โ
docker run, K8s args
|
| ENTRYPOINT | ๐ When running container | Fixed execution command |
โ
K8s command
|
RUN โ Multi-run declaration
yaml
RUN apt-get install -y curl
CMD โ one-time declaration
yaml
CMD ["nginx", "-g", "daemon off;"]
- If only CMD is written without ENTRYPOINT, full override is possible with
K8s command - If ENTRYPOINT exists, CMD is always applied as the argument value of ENTRYPOINT
ENTRYPOINT โ 1-time declaration
yaml
ENTRYPOINT ["nginx"]
Features
Understanding the difference between CMD and ENTRYPOINT
- The static performance of the two below is the same.
docker
#1
ENTRYPOINT ["python3"]
CMD ["app.py"]
#2
ENTRYPOINT ["python3", "app.py"]
- CMD can be overridden with the argument value of the
dockercommand.
bash
docker run myimage test.py
- The resulting ENTRYPOINT
bash
#1
python3 test.py
#2
python3 app.py
Jar Sample1
bash
FROM $baseImage
ADD $jarfile /app
WORKDIR /app
USER $user
ENTRYPOINT ["java", "-Dfile.encoding=UTF8", "-Duser.timezone=Asia/Seoul", "-jar", "$jarfile"]
War Sample โ Springboot War
bash
FROM $baseImage
ADD $warfile /app
WORKDIR /app
USER $user
ENTRYPOINT ["java", "-Dfile.encoding=UTF8", "-Duser.timezone=Asia/Seoul", "-jar", "$warfile"]
War Sample โ Spring War โTODO
bash
# Step 1: Use an official Tomcat base image
FROM tomcat:9.0-jdk11
# Step 2: Remove the default ROOT application
RUN rm -rf /usr/local/tomcat/webapps/ROOT
# Step 3: Copy your WAR file into the container
COPY myapp.war /usr/local/tomcat/webapps/ROOT.war
# Step 4: Expose the default Tomcat port
EXPOSE 8080
# Step 5: Start Tomcat
CMD ["catalina.sh", "run"]
War Sample โ Spring War โ Multi-Stage (Maven Build during Docker build)
bash
# Stage 1: Build the application
FROM maven:3.8.6-openjdk-11 AS builder
WORKDIR /app
# Copy source files
COPY src /app/src
COPY pom.xml /app
# Package the application
RUN mvn clean package -DskipTests
# Stage 2: Deploy to Tomcat
FROM tomcat:9.0-jdk8
WORKDIR /usr/local/tomcat
# Remove default ROOT application
RUN rm -rf ./webapps/ROOT
# Copy WAR file from the build stage
COPY --from=builder /app/target/demo2-1.0-SNAPSHOT.war ./webapps/ROOT.war
# Expose the default Tomcat port
EXPOSE 8080
# Start Tomcat
CMD ["sh", "-c", "sh ./bin/catalina.sh run"]
- Commands
bash
docker build -t test.io/demo2:latest . --platform=linux/amd64
docker run -d -p 80:8080 test.io/demo2:latest
Add openssh-client to Alpine image
bash
FROM alpine:latest
# Install the OpenSSH client
RUN apk --no-cache add openssh-clien
# Your other Dockerfile instructions here
CMD ["/bin/sh"]




Leave a Reply