-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdockerfile
More file actions
38 lines (26 loc) · 885 Bytes
/
dockerfile
File metadata and controls
38 lines (26 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Use a Linux base image as base image for building
FROM alpine:3.17 as builder
# Set the working directory in the container
WORKDIR /app
# Create a non-root user for security
RUN adduser -D myuser
# Copy only the dependencies file to the working directory
COPY requirements.txt .
# Install dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Copy the entire code directory into the container
COPY . .
# Compile the Python code to binary using pyinstaller
RUN pyinstaller --onefile load_balancer.py
# Switch to the non-root user
USER myuser
# Final image stage, using the same Alpine image
FROM alpine:3.17
# Copy the compiled binary from the builder stage
COPY --from=builder /app/dist/main /app/main
# Set the working directory
WORKDIR /app
# Expose the port
EXPOSE 5000
# Run the compiled binary
CMD ["./load_balancer"]