Skip to content

Updated Dockerfile with Feature and Compatibility #4657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 48 additions & 11 deletions scripts/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,68 @@
# If you are using windows, run the below command to make it compatible
# dos2unix /usr/local/memos/entrypoint.sh

# Below is Updated Dockerfile

# Step 1: Build frontend
FROM node:20-alpine AS frontend
WORKDIR /app/web

# Copy the necessary files for the frontend build
COPY ./web/ /app/web/
COPY ./proto/ /app/proto/

# Install pnpm and dependencies
RUN npm install -g pnpm
RUN pnpm install --frozen-lockfile
RUN pnpm run release

# Step 2: Build Go backend
FROM golang:1.24-alpine AS backend
WORKDIR /backend-build
COPY go.mod go.sum ./
RUN go mod download

# Copy the necessary files for the Go backend build
COPY . .
# Please build frontend first, so that the static files are available.
# Refer to `pnpm release` in package.json for the build command.
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
go build -ldflags="-s -w" -o memos ./bin/memos/main.go

# Make workspace with above generated files.
# Copy built frontend into the backend location
COPY --from=frontend /app/server/router/frontend/dist /backend-build/server/router/frontend/dist

# Build the Go binary
RUN go build -o memos ./bin/memos/main.go

# Step 3: Final image
FROM alpine:latest AS monolithic
WORKDIR /usr/local/memos

RUN apk add --no-cache tzdata
# Install dependencies (including bash if needed)
RUN apk add --no-cache tzdata bash

# Set timezone environment variable
ENV TZ="UTC"

# Copy the built Go binary and entrypoint script
COPY --from=backend /backend-build/memos /usr/local/memos/
COPY ./scripts/entrypoint.sh /usr/local/memos/
COPY scripts/entrypoint.sh /usr/local/memos/

# Ensure entrypoint and binary are executable
RUN chmod +x /usr/local/memos/memos /usr/local/memos/entrypoint.sh

# Expose the port for the application
EXPOSE 5230

# Directory to store the data, which can be referenced as the mounting point.
# Set the volume for data persistence
RUN mkdir -p /var/opt/memos
VOLUME /var/opt/memos

# Set environment variables for the application
ENV MEMOS_MODE="prod"
ENV MEMOS_PORT="5230"

# NOTE: if you want to Connect to External Database
# E.g. GCP Cloud SQL , then uncomment below code and
# Replace Password -> with Database Password
# Replace IP -> with your DB Server IP
# ENV MEMOS_DRIVER=mysql
# ENV MEMOS_DSN=root:password@tcp(34.58.50.141:3306)/memos_prod

# Define the entrypoint command
ENTRYPOINT ["./entrypoint.sh", "./memos"]