With Application Hosting, you can use a Dockerfile to set up your container image. Using a Dockerfile gives you more control, and you can use almost any language, so you are not restricted to the languages Nixpacks or Buildpacks support.

A Dockerfile sets up the environment depending on the instructions within the Dockerfile, which must include commands to install the language, adjacent software, and libraries, set up the port, and start the web server. Kinsta automatically sets the PORT environment variable. You do not need to define it yourself or hard-code it into the application. For example, in Node.js, use process.env.PORT in your code when referring to the server port.

Detailed information about how to create a Dockerfile is available in Docker Docs.

Dockerfile Settings

To use a Dockerfile, when you add an application, select the option to Use Dockerfile to set up container image in the Build environment.

The Dockerfile path is the path to your Dockerfile relative to the repository root. For example, if your Dockerfile is in the repository root, enter Dockerfile in that field. If your Dockerfile is in a subdirectory named app, enter the path to the Dockerfile: app/Dockerfile.

Context is the path in the repository we need access to so we can build your application. Most applications are built from the repository root, and you can enter the repository root (.) in the Context field. If your application needs to be built from a subdirectory (e.g. app), enter that subdirectory path in the Context field: app.

Complete the rest of the fields for adding your application and click Add application.

Add an application with a Dockerfile build type.
Add an application with a Dockerfile build type.

Example Dockerfile

To help get you started, here’s an example Dockerfile you can use for reference or as a starting point.

FROM node:carbon

LABEL maintainer="Kinsta devs"

# Set the working directory to /app

# Copy the current directory contents into the container at /app
COPY . /app

# Install any needed packages specified in package.json
RUN npm install

# Run app when the container launches
CMD ["npm", "start"]

Host a Database With a Dockerfile

If you combine persistent storage and a Dockerfile, you can host pretty much any database you want with our Application Hosting. Even something like a Microsoft SQL Server database, which isn’t supported on our Database Hosting, can be deployed. If you can containerize it with a Dockerfile, you can deploy it on Application Hosting.

Persistent storage is needed to retain the data in your database. If you deploy a database on Application Hosting without persistent storage, all data will be lost if the application is restarted or redeployed.

Docker images for many databases can be found at Docker Hub. Look for the Docker Official Image badge when searching for a database to get the most secure and well-documented images that follow best practices.

Was this article helpful?