Getting Started with Nixpacks

nwby

Sam Newby

Posted on October 15, 2024

Getting Started with Nixpacks

Building images without a Dockerfile with Nixpacks

Nixpacks is a tool created by the Railway team which allows you to build OCI compliant images without having to write a Dockerfile. Essentially you can run Nixpacks in your repository, it will automatically figure out how to build your repo into an image and then build that image that you can then run with docker run. Pretty amazing right?

Installation

Installing Nixpacks is pretty easy, you can just run:

curl -sSL https://nixpacks.com/install.sh | bash
Enter fullscreen mode Exit fullscreen mode

on any platform and it will install.

Building our first image

Right now that we've got Nixpacks installed with that incredibly easy install, we can build our first image. If you don't have a repo to hand then you can clone this demo repo built by the Vizalo team to showcase our new managed application service. Clone the repo to your machine by running:

git clone git@github.com:vizalo/app-0.git
Enter fullscreen mode Exit fullscreen mode

Now we can run nixpacks build . --name app-0 to let nixpacks build the image. Let's break this command down:

  1. We're running the nixpacks build command
  2. We're telling nixpacks to use this directory by using .
  3. We're then giving the image a name which is easy for us to remember with the --name flag

Give it a minute or two and we will have an image which we can run with docker run -it app-0

But wait! What's that nixpacks.toml file? Well that is a configuration file that we can add to our repo to provide nixpacks with some custom instructions. Why do we need it? Well our repo doesn't actually have a start command for production, so nixpacks won't be able to define a command to start our code in the image. So we manually tell it to run node ./dist/index.mjs to start our code. If your repo has a command to start in production, maybe you've defined a npm run start command then you should be good and nixpacks will automatically use that.

Finishing up

This has been a whirlwind introduction to nixpacks, and to cleanup our machine we can remove Nixpacks by running rm "$(command -v 'nixpacks')".

💖 💪 🙅 🚩
nwby
Sam Newby

Posted on October 15, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Getting Started with Nixpacks
nixpacks Getting Started with Nixpacks

October 15, 2024