In this tutorial, we are going to create an OCI image (Docker image) from a Qwik application without providing a Dockerfile. We can do this with a tool called Buildpacks. In a previous article, we already discussed how to build and run Qwik in Docker.

At the time of writing the latest version of Qwik is 0.16.1 and Qwik City 0.0.128.

Let’s assume that you have NPM, Node and Docker already installed.

Setting up a Qwik project

We are going to set up a new Qwik project and add the Express adaptor. To do this we follow the steps “Generate Qwik project” and “Adding the Express adaptor” from a previous tutorial.

We named our Qwik application qwik-buildpack-app.

Building the OCI image

Now that we have our Qwik application we can start building the OCI image with Buildpack.

Installing Pack CLI

First, install the Pack CLI tool. We will follow the Buildpack documentation for this.

Verify that Pack is successfully installed.

pack version

Setting the default builder

We are going to set up heroku/buildpacks as our default builder for this tutorial. There are other builders as well that you can use, some well-known builders are Paketo Buildpacks and Google Cloud Buildpacks.

To use the Pack CLI, the Docker daemon should be running. We can verify that the Docker daemon is running with:

docker version

Then set the default builder to heroku/buildpacks.

pack config default-builder heroku/buildpacks

Adding a Procfile

A Procfile is a simple text file without extension that specifies commands that are run when the container starts up. This Procfile should always be placed in the root of the application.

The default startup point when creating a NodeJS OCI image with Buildpack is npm start but sometimes you don’t want this. We can leverage the Procfile to override the startup behavior of the container.

Open the root of the Qwik application in a terminal.

We can add the Procfile via the CLI or we can do this manually.

 echo "web: node server/entry.express" > Procfile

Building the application with Pack

Now we are going to build the OCI image with Pack. Make sure that your terminal is opened at the root of the Qwik project.

pack build qwik-buildpack-app

Running the Qwik app with Docker

When the build completes we can run the OCI image with Docker.

docker run -p 3000:3000 qwik-buildpack-app

Open a browser on http://localhost:3000 to see the Qwik application running.

Conclusion

Congratulations, we just build an OCI image (Docker image) from a Qwik application without a Dockerfile.

In my humble opinion, Buildpacks are ideal for simple projects when you don’t have a Dockerfile at hand. In more complex situations it may be better to write Dockerfiles.