-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
70 lines (50 loc) · 1.21 KB
/
Dockerfile
File metadata and controls
70 lines (50 loc) · 1.21 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Build stage
FROM elixir:1.15-alpine AS builder
# Install build dependencies
RUN apk add --no-cache build-base git
# Set environment variables
ENV MIX_ENV=prod
# Create app directory
WORKDIR /app
# Install hex and rebar
RUN mix local.hex --force && \
mix local.rebar --force
# Copy mix files
COPY mix.exs ./
# Install dependencies
RUN mix deps.get --only prod
RUN mix deps.compile
# Copy source code
COPY . .
# Compile assets
RUN mix assets.deploy
# Compile the application
RUN mix compile
# Create release
RUN mix release
# Runtime stage
FROM alpine:3.18
# Install runtime dependencies
RUN apk add --no-cache \
openssl \
ncurses-libs \
libgcc \
libstdc++
# Create non-root user
RUN adduser -D -s /bin/sh app
# Set working directory
WORKDIR /app
# Copy release from builder stage
COPY --from=builder --chown=app:app /app/_build/prod/rel/simple_elixir_app ./
# Switch to non-root user
USER app
# Expose port
EXPOSE 4000
# Set environment
ENV MIX_ENV=prod
ENV PORT=4000
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:4000/ || exit 1
# Start the application
CMD ["./bin/simple_elixir_app", "start"]