Dockerfile Deployment on High-Performance MicroVMs is GA5 min
Today, we are excited to announce the support of Dockerfile based deployments in general availability.
Building and deploying using Dockerfiles offers more flexibility: you can deploy any kind of application, framework, and runtime, including with custom system dependencies. This means you can now deploy .NET, Rust, Zig, Bun, Crystal, Deno, or any framework: you add a Dockerfile, you push, we build and run it.
We now offer three different methods to deploy your applications close to your users:
- Build from Dockerfile: Deploy any GitHub repositories containing a Dockerfile and benefit of continuous deployment via a simple
- Cloud Native Buildpacks: Deploy GitHub repositories with code in Node.js, Python, Go, Ruby, Java, PHP, Scala, and Clojure, we will detect your runtime and automatically build it
- Pre-built containers: Deploy pre-built container images from any registry with a single API call and keep control of the build process.
Let’s jump in and check how to build and deploy an application using a Dockerfile with the Koyeb control panel.
Now let's explore two important features to customize your docker builds:
- Build customization with docker build args and environment variables
- Multi-stage builds and specific target deployment
Customize build with environment variables and docker build args
For dockerized applications that need to access environment variables at build time, you can use the
ARG command in your Dockerfile to access your Koyeb Services’ environment variables.
This is useful when you need to customize your build.
Let’s take this minimalistic Dockerfile as an example:
Here, we use the
ARG directive to define the
NGINX_VERSION variable. When this variable is set, the
FROM instruction will use the specified Nginx version as the base image. Otherwise, the
latest default tag will be used.
To deploy the following Dockerfile and set the
NGINX_VERSION variable using the Koyeb CLI, we then just have to run the following command:
This command will create a new Koyeb App and Service and deploy the
main branch of a GitHub repository, use
docker as a builder, and set the Service environment variable
1.25. If the environment variable is not set, it will default to the latest version.
The way the platform will build the container in the example above is similar to running the following command locally with Docker:
Deploy a specific target in a multi-stage build
Multi-stage builds offer a way to create Docker images optimized for different environments.
If you have a multi-stage Dockerfile, you can select the target stage to run on Koyeb. This can be useful when your Dockerfile contains a target for multiple environments and you want to specifically run one of the environments.
Here is how this works with our previous Dockerfile updated with two stages:
In the snippet above, we define two targets: debug and production. The target names are defined by adding an AS after the FROM directives.
debug target launches Nginx in debug mode and the default
production target in production mode.
Then to run one of these targets on Koyeb using the CLI, execute the following command:
--git-docker-target flag specifies the
debug target to override the default
Koyeb will build the container in much the same way as the following Docker command:
Faster build thanks to cache
To accelerate your deployments, we automatically cache each layer when building Dockerfiles. Each time you push a new version of your application, we reuse those layers to speed up the build process and get you live faster.
In some cases, you might also want to clear the cache. To perform this action using the CLI, you just have to deploy your Service by running the following command:
Start deploying your Dockerized applications on Koyeb today!
We are excited to announce the general availability of build from Dockerfile on Koyeb to offer more flexibility and control over the build process of your applications while enjoying built-in continuous deployment capabilities provided by Koyeb.
With Koyeb's built-in continuous deployment, multi-region deployments across continents, global load balancing across our edge network of 250+ locations, and zero-configuration private networking deploying web services or workers in production takes only a few minutes.
Sign up today and start deploying for free with $5.50 of credit granted to your account every month.