Home

Awesome

Dockerfile Generator

new-dockerfile is a CLI tool and Go package automatically generates a configurable Dockerfile based on your project source code. It supports a wide range of languages and frameworks, including Next.js, Node.js, Python, Ruby, Java/Spring Boot, Go, Elixir/Phoenix, and more.

See the FlexStack Documentation page for FlexStack-specific documentation related to this tool.

Features

Supported Runtimes

Additional runtimes we'd like to support

Consider contributing to add support for these or any other runtimes!

Installation

cURL

curl -fsSL https://flexstack.com/install/new-dockerfile | bash

Go Package

go get github.com/flexstack/new-dockerfile

CLI Usage

new-dockerfile [options]

CLI Options

CLI Examples

Print the generated Dockerfile to the console:

new-dockerfile

Write a Dockerfile to the current directory:

new-dockerfile --write

Write a Dockerfile to a specific directory:

new-dockerfile > path/to/Dockerfile

Force a specific runtime:

new-dockerfile --runtime next.js

List the supported runtimes:

new-dockerfile --runtime list

Read from Config file

In the CI use case, you might need a very common step for generating a Dockerfile. You can create a config file for the CLI options. The default config file name is new-dockerfile.yaml, and it should be in the root directory of your git repository. Especially, there are multiple kinds of files, new-dockerfile might not be able to it a correct one.

runtime: go

And, the CLI option will overwrite the values from config file.

How it Works

The tool searches for common files and directories in your project to determine the runtime and framework. For example, if it finds a package.json file, it will assume the project is a Node.js project unless a next.config.js file is present, in which case it will assume the project is a Next.js project.

From there, it will read any .tool-versions or other version manager files to determine the correct version of the runtime to install. It will then make a best effort to detect any install, build, and start commands. For example, a serve, start, start:prod command in a package.json file will be used as the start command.

Runtimes are matched against in the order they appear when you run new-dockerfile --runtime list.

Read on to see runtime-specific examples and how to configure the generated Dockerfile.

Runtime Documentation

Bun

Bun is a fast JavaScript all-in-one toolkit

Detected Files

Version Detection

Runtime Image

oven/bun:${VERSION}-slim

Build Args

Build Command

Detected in order of precedence:

Start Command

Detected in order of precedence:


Deno

Deno is a secure runtime for JavaScript with native TypeScript and JSX support

Detected Files

Version Detection

Runtime Image

debian:stable-slim

Build Args

Install Command

Detected in order of precedence:

Start Command

Detected in order of precedence:


Elixir

Elixir is a dynamic, functional language designed for building scalable and maintainable applications.

Detected Files

Version Detection

Runtime Image

debian:stable-slim

Build Args

Start Command

/app/bin/{BIN_NAME} start


Go

Go is an open-source programming language that makes it easy to build simple, reliable, and efficient software.

Detected Files

Version Detection

Runtime Image

debian:stable-slim

Build Args

Package Detection

Install Command

if [ -f go.mod ]; then go mod download; fi

Build Command

CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -trimpath -ldflags="-s -w" -o /go/bin/app "${PACKAGE}"

Start Command

["/app/app"]


Java

Java is a class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible.

Detected Files

Version Detection

JDK version:

Runtime Image

eclipse-temurin:${VERSION}-jdk

Build Args

Install Command

Build Command

Start Command


Next.js

Next.js is a React framework that enables functionality such as server-side rendering and generating static websites.

Detected Files

Version Detection

Runtime Image

node:${VERSION}-slim

Build Args

Install Command

if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f bun.lockb ]; then npm i -g bun && bun install; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi

Build Command

if [ -f yarn.lock ]; then yarn run build; \
elif [ -f package-lock.json ]; then npm run build; \
elif [ -f bun.lockb ]; then npm i -g bun && bun run build; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
else echo "Lockfile not found." && exit 1; \
fi

Start Command


Node.js

Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine.

Detected Files

Version Detection

Runtime Image

node:${VERSION}-slim

Build Args

Install Command

Build Command

In order of precedence:

Start Command

In order of precedence:


PHP

PHP is a popular general-purpose scripting language that is especially suited to web development.

Detected Files

Version Detection

Runtime Image

php:${VERSION}-apache

Build Args

Install Command

Build Command

Start Command

apache2-foreground


Python

Python is a high-level, interpreted programming language that is known for its readability and simplicity.

Detected Files

Version Detection

Runtime Image

python:${VERSION}-slim

Build Args

Install Command

Start Command


Ruby

Ruby is a dynamic, open-source programming language with a focus on simplicity and productivity.

Detected Files

Version Detection

Runtime Image

ruby:${VERSION}-slim

Build Args

Install Command

Build Command

Start Command


Rust

Rust is a systems programming language that is known for its speed, memory safety, and parallelism.

Detected Files

Runtime Image

debian:stable-slim

Build Args

Build Command

if [ "${TARGETARCH}" = "amd64" ]; then rustup target add x86_64-unknown-linux-gnu; else rustup target add aarch64-unknown-linux-gnu; fi
if [ "${TARGETARCH}" = "amd64" ]; then cargo zigbuild --release --target x86_64-unknown-linux-gnu; else cargo zigbuild --release --target aarch64-unknown-linux-gnu; fi

Start Command

Determined by the binary name in the Cargo.toml file


Static (HTML, CSS, JS)

Static Web Server is a cross-platform, high-performance & asynchronous web server for static files serving. It is nearly as fast as Nginx and Lighttpd, but is easily configurable with environment variables.

Detected Files

Runtime Image

joseluisq/static-web-server:${VERSION}-debian

Build Args


Used By

Contributing

Read the CONTRIBUTING.md guide to learn how to contribute to this project.

License

This project is licensed under the MIT License - see the LICENSE file for details.