Skip to content

Optimize Docker image build - #279

Open
ChaoticSciuridae wants to merge 1 commit into
kikootwo:mainfrom
ChaoticSciuridae:docker/multistage-build
Open

ChaoticSciuridae wants to merge 1 commit into
kikootwo:mainfrom
ChaoticSciuridae:docker/multistage-build

Conversation

@ChaoticSciuridae

Copy link
Copy Markdown

This converts dockerfile.unified to a multi-stage build while trying to change as little as possible about the existing runtime behavior.

I'm not a Docker expert but I noticed the image was much larger than any of my other services because the existing build installed build/dev dependencies into the same image that ultimately became the runtime image.

The main goal here was simply: reduce the image size as much as practical with the smallest possible change.

So with the help of AI to bridge my knowledge gaps --

Results

Built on the same machine:

  • Before: ~1.05 GB
  • After: ~728 MB
  • Reduction: ~322 MB / ~31%

The builder now handles the dependencies and files needed to build the Next.js application, while the final runtime stage only receives what it needs to run.

I intentionally avoided trying to redesign the container, split PostgreSQL/Redis into separate services, change the startup process, or otherwise expand the scope of this PR.

Testing

I built and ran the resulting image locally.

So far:

  • Container starts successfully
  • Application/server is accessible
  • Startup logs showed no obvious errors
  • Prisma startup operations completed
  • Internal services started normally

The application appears to behave normally in my testing.

Again, Docker image optimization isn't really my area of expertise, so feedback is very welcome if there is a better way to handle any of the stage boundaries or runtime dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant