When you deploy a GitHub repo to FlexStack, you don't explicitly need a Dockerfile. If we don't detect one in your repository, we'll attempt to generate one for you automatically based on your project's source code. This will work perfectly for the vast majority of cases, but if you find yourself needing more customization you may bring your own Dockerfile.
How it works
We search for common files and directories in your project to determine the runtime and framework you're using. For example, if we find a package-lock.json
file, we 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, we will detect any .tool-versions
or other version manager files to determine the correct version of the runtime to install. Then, we 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.
Read on to see runtime-specific examples and how to configure the generated Dockerfile.
Customizing the generated Dockerfiles
All of the Dockerfiles we generate have Docker Build Arguments that make them configurable from the FlexStack dashboard. To do so, visit the Build tab in your FlexStack component.
If you need more customization, we suggest downloading our new-dockerfile CLI tool and using it directly within your project.
Features
- Automatically detects the runtime and framework used by your project
- Uses version managers like asdf, nvm, rbenv, and pyenv to install the correct version of the runtime
- Makes a best effort to detect any install, build, and start commands
- Generates a Dockerfile with sensible defaults that are configurable via Docker Build Args
- Supports a wide range of the most popular languages and frameworks including Next.js, Phoenix, Spring Boot, Django, and more
- Uses Debian Slim as the runtime image for a smaller image size and better security, while still supporting the most common dependencies and avoiding deployment headaches caused by Alpine Linux gotchas
- Includes
wget
in the runtime image for adding health checks to services, e.g.wget -nv -t1 --spider 'http://localhost:8080/healthz' || exit 1
- Uses multi-stage builds to reduce the size of the final image
- Runs the application as a non-root user for better security
- Supports multi-platform images that run on both x86 and ARM CPU architectures
Supported runtimes
- Bun
- Deno
- Elixir
- Go
- Java
- Next.js
- Node.js
- PHP
- Python
- Ruby
- Rust
- Static (HTML, CSS, JS)
Additional runtimes we'd like to support
- C#/.NET
- C++
- Scala
- Zig
Consider contributing to add support for these or any other runtimes!
Alternatives for generating Dockerfiles
- new-dockerfile - Our CLI tool used for generating Dockerfiles from your project source code
- @flyio/dockerfile - A tool for generating Dockerfiles for Node.js code
Runtime Documentation
Bun
Bun is a fast JavaScript all-in-one toolkit
Detected Files
bun.lockb
bunfig.toml
Version Detection
.tool-versions
-bun {VERSION}
Runtime Image
oven/bun:${VERSION}-slim
Build Args
VERSION
- The version of Bun to install (default:1
)INSTALL_CMD
- The command to install dependencies (default:bun install
)BUILD_CMD
- The command to build the project (default: detected frompackage.json
)START_CMD
- The command to start the project (default: detected frompackage.json
)
Build Command
Detected in order of precedence:
package.json
scripts:"build:prod", "build:production", "build-prod", "build-production", "build"
Start Command
Detected in order of precedence:
package.json
scripts:"serve", "start:prod", "start:production", "start-prod", "start-production", "preview", "start"
package.json
main/module file:bun run ${mainFile}
Deno
Deno is a secure runtime for JavaScript with native TypeScript and JSX support
Detected Files
deno.jsonc
deno.json
deno.lock
deps.ts
mod.ts
Version Detection
.tool-versions
-deno {VERSION}
Runtime Image
debian:stable-slim
Build Args
VERSION
- The version of Deno to install (default:latest
)INSTALL_CMD
- The command to install dependencies (default: detected fromdeno.jsonc
and source code)START_CMD
- The command to start the project (default: detected fromdeno.jsonc
and source code)
Install Command
Detected in order of precedence:
deno.jsonc
tasks:"cache"
- Main/module file:
deno cache ["mod.ts", "src/mod.ts", "main.ts", "src/main.ts", "index.ts", "src/index.ts]"
Start Command
Detected in order of precedence:
deno.jsonc
tasks:"serve", "start:prod", "start:production", "start-prod", "start-production", "preview", "start"
- Main/module file:
deno run ["mod.ts", "src/mod.ts", "main.ts", "src/main.ts", "index.ts", "src/index.ts]"
Elixir
Elixir is a dynamic, functional language designed for building scalable and maintainable applications.
Detected Files
mix.exs
Version Detection
.tool-versions
-elixir {VERSION}
.tool-versions
-erlang {VERSION}
.elixir-version
-{VERSION}
.erlang-version
-{VERSION}
Runtime Image
debian:stable-slim
Build Args
VERSION
- The version of Elixir to install (default:1.12
)OTP_VERSION
- The version of Erlang to install (default:26.2.5
)BIN_NAME
- The name of the release binary (default: detected via app name inmix.exs
)
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
go.mod
main.go
Version Detection
.tool-versions
-golang {VERSION}
go.mod
-go {VERSION}
Runtime Image
debian:stable-slim
Build Args
VERSION
- The version of Go to install (default:1.17
)TARGETOS
- The target OS for the build (default:linux
)TARGETARCH
- The target architecture for the build (default:amd64
)CGO_ENABLED
- Enable CGO for the build (default:0
)GOPROXY
- The Go module proxy to use (default:direct
)PACKAGE
- The package to compile e.g../cmd/http
(default: detected viacmd
directory ormain.go
)
Package Detection
- Find the directory in
cmd
with a.go
file main.go
file in the root directory
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
build.gradle
gradlew
pom.{xml,atom,clj,groovy,rb,scala,yml,yaml}
Version Detection
JDK version:
.tool-versions
-java {VERSION}
Gradle version:.tool-versions
-gradle {VERSION}
Maven version:.tool-versions
-maven {VERSION}
Runtime Image
eclipse-temurin:${VERSION}-jdk
Build Args
VERSION
- The version of the JDK to install (default:17
)GRADLE_VERSION
- The version of Gradle to install (default:8
)MAVEN_VERSION
- The version of Maven to install (default:3
)JAVA_OPTS
- The Java options to pass to the JVM (default:-Xmx512m -Xms256m
)BUILD_CMD
- The command to build the project (default: best guess via source code)START_CMD
- The command to start the project (default: detected via source code)
Install Command
- If Maven:
mvn install
Build Command
- If Maven:
mvn -DoutputFile=target/mvn-dependency-list.log -B -DskipTests clean dependency:list install
- If Gradle:
./gradlew clean build -x check -x test
Start Command
- Default:
java $JAVA_OPTS -jar target/*jar
- If Gradle:
java $JAVA_OPTS -jar $(ls -1 build/libs/*jar | grep -v plain)
- If Spring Boot:
java -Dserver.port=${PORT} $JAVA_OPTS -jar target/*jar
- If Spring Boot w/ Gradle:
java -Dserver.port=${PORT} $JAVA_OPTS -jar $(ls -1 build/libs/*jar | grep -v plain)
Next.js
Next.js is a React framework that enables functionality such as server-side rendering and generating static websites.
Detected Files
next.config.{js,mjs,cjs,ts,mts}
next-env.d.ts
.next/
Version Detection
.tool-versions
-nodejs {VERSION}
.nvmrc
-v{VERSION}
.node-version
-v{VERSION}
Runtime Image
node:${VERSION}-slim
Build Args
VERSION
- The version of Node.js to install (default:lts
)
Install Command
Build Command
Start Command
- If
"output" :"standalone"
innext.config.js
:HOSTNAME="0.0.0.0" node server.js
- Otherwise
["node_modules/.bin/next", "start", "-H", "0.0.0.0"]
Node.js
Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine.
Detected Files
yarn.lock
package-lock.json
pnpm-lock.yaml
Version Detection
.tool-versions
-nodejs {VERSION}
.nvmrc
-v{VERSION}
.node-version
-v{VERSION}
Runtime Image
node:${VERSION}-slim
Build Args
VERSION
- The version of Node.js to install (default:lts
)INSTALL_CMD
- The command to install dependencies (default: detected from source code)BUILD_CMD
- The command to build the project (default: detected from source code)START_CMD
- The command to start the project (default: detected from source code)
Install Command
- If Yarn:
yarn --frozen-lockfile
- If npm:
npm ci
- If pnpm:
corepack enable pnpm && pnpm i --frozen-lockfile
Build Command
In order of precedence:
package.json
scripts:"build:prod", "build:production", "build-prod", "build-production", "build"
Start Command
In order of precedence:
package.json
scripts:"serve", "start:prod", "start:production", "start-prod", "start-production", "preview", "start"
package.json
scripts search for regex matching:^.*?\b(ts-)?node(mon)?\b.*?(index|main|server|client)\.([cm]?[tj]s)\b
package.json
main/module file:node ${mainFile}
PHP
PHP is a popular general-purpose scripting language that is especially suited to web development.
Detected Files
composer.json
index.php
Version Detection
.tool-versions
-php {VERSION}
composer.json
-"php": "{VERSION}"
Runtime Image
php:${VERSION}-apache
Build Args
VERSION
- The version of PHP to install (default:8.3
)INSTALL_CMD
- The command to install dependencies (default: detected via source code)BUILD_CMD
- The command to build the project (default: detected via source code)START_CMD
- The command to start the project (default:apache2-foreground
)
Install Command
- If Composer:
composer update && composer install --prefer-dist --no-dev --optimize-autoloader --no-interaction
- If
package.json
exists: composer install command + see Node.js install command
Build Command
- If
package.json
exists: see Node.js 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
requirements.txt
poetry.lock
Pipefile.lock
pyproject.toml
pdm.lock
main.py
app.py
application.py
app/__init__.py
filepath.Join(filepath.Base(path), "app.py")
filepath.Join(filepath.Base(path), "application.py")
filepath.Join(filepath.Base(path), "main.py")
filepath.Join(filepath.Base(path), "__init__.py")
Version Detection
.tool-versions
-python {VERSION}
.python-version
-{VERSION}
runtime.txt
-python-{VERSION}
Runtime Image
python:${VERSION}-slim
Build Args
VERSION
- The version of Python to install (default:3.10
)INSTALL_CMD
- The command to install dependencies (default: detected from source code)START_CMD
- The command to start the project (default: detected from source code)
Install Command
- If Poetry:
poetry install --no-dev --no-interactive --no-ansi
- If Pipenv:
PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy
- If PDM:
pdm install --prod
- If
pyproject.toml
exists:pip install --upgrade build setuptools && pip install .
- If
requirements.txt
exists:pip install -r requirements.txt
Start Command
- If Django is detected:
python manage.py runserver 0.0.0.0:${PORT}
- If
pyproject.toml
exists:python -m ${projectName}
- Otherwise:
python [main.py, app.py, application.py, app/main.py, app/application.py, app/__init__.py]
Ruby
Ruby is a dynamic, open-source programming language with a focus on simplicity and productivity.
Detected Files
Gemfile
Gemfile.lock
config.ru
Rakefile
config/environment.rb
Version Detection
.tool-versions
-ruby {VERSION}
.ruby-version
-{VERSION}
Gemfile
-ruby '{VERSION}'
Runtime Image
ruby:${VERSION}-slim
Build Args
VERSION
- The version of Ruby to install (default:3.0
)INSTALL_CMD
- The command to install dependencies (default: detected from source code)BUILD_CMD
- The command to build the project (default: detected from source code)START_CMD
- The command to start the project (default: detected from source code)
Install Command
bundle install
- If
package.json
exists:bundle install && [package manager install command]
Build Command
- If Rails:
bundle exec rake assets:precompile
Start Command
- If Rails:
bundle exec rails server -b 0.0.0.0 -p ${PORT}
- If
config.ru
exists:bundle exec rackup config.ru -p ${PORT}
- If
config/environment.rb
exists:bundle exec rails server -b
- If
Rakefile
exists:bundle exec rake
Rust
Rust is a systems programming language that is known for its speed, memory safety, and parallelism.
Detected Files
Cargo.toml
Runtime Image
debian:stable-slim
Build Args
TARGETOS
- The target OS for the build (default:linux
)TARGETARCH
- The target architecture for the build (default:amd64
)BIN_NAME
- The name of the release binary (default: detected viaCargo.toml
)
Build Command
Start Command
Determined by the binary name in the Cargo.toml
file
["/app/app"]
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
public/
static/
dist/
index.html
Runtime Image
joseluisq/static-web-server:${VERSION}-debian
Build Args
VERSION
- The version of the static web server to install (default:2
)SERVER_ROOT
- The root directory of the server (default: detected from source code)