Skip to content

Commit

Permalink
update custom docker runtime doc (#520)
Browse files Browse the repository at this point in the history
  • Loading branch information
davemooreuws authored Mar 18, 2024
1 parent 12d54a3 commit b05e3a4
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions src/pages/assets/custom-containers.mdx
Original file line number Diff line number Diff line change
@@ -1,41 +1,37 @@
export const description = 'Customize how services are built into containers'

# Custom containers
# Custom container runtimes

Nitric builds applications by identifying its entrypoints, which are typically defined in the `nitric.yaml` file as `handlers`. Each entrypoint in a Nitric app is built into its own container using Docker, then deployed to a cloud container runtime such as AWS Lambda, Google CloudRun or Azure Container Apps.
Nitric builds applications by identifying its entrypoints, which are typically defined in the `nitric.yaml` file as `services`. Each entrypoint in a Nitric app is built into its own container using Docker, then deployed to a cloud container runtime such as AWS Lambda, Google CloudRun or Azure Container Apps.

The Nitric CLI decides how to build those containers based on the programming language used by the entrypoint, for example if the entrypoint is a python file it will be built using Nitric's python dockerfile template. These dockerfile templates are designed with compatibility and ease of use in mind, this makes building applications convenient but may not provide additional dependencies your code relies on the ideal optimization for your application.

If you need to customize the docker container build process to add dependencies, optimize container size or some other reason, you can create a custom dockerfile template to be used by some or all of the entrypoints (services) in your application.

## Specify a dockerfile template
## Add a new custom runtime

<Note>
Custom dockerfiles is currently in preview, you will need to enable this
feature in your `nitric.yaml` file.
</Note>
Add a new custom runtime in the `runtimes` configuration.

To use a custom dockerfile template update the `handlers` configuration as shown below.
To use the runtime, simply specify the runtime key per service as shown below.

```yaml {{ tag: "nitric.yaml" }}
name: custom-example
handlers:
services:
- match: services/*.ts
type: default
docker:
# All entrypoints in the services directory will be built using this dockerfile
file: ./docker/node.dockerfile
args: {}
# Enable preview feature
preview-features:
- dockerfile
runtime: 'custom-node' # specify custom runtime
start: npm run dev:services $SERVICE_PATH
runtimes:
custom-node:
# All services that specify the 'custom-node' runtime will be built using this dockerfile
dockerfile: ./docker/node.dockerfile
args: {}
```
In this example we're specifying that any handlers that match the path `services/*.ts` will use a custom `node.dockerfile` for their dockerfile template.

## Create a dockerfile template

It's important to note that the custom dockerfile you create needs to act as a template. This can look a bit different to how you might have written dockerfiles in the past, since the same template file will need to be used for all handlers that match the configuration the entrypoint will use a variable which contains the handler's filename.
It's important to note that the custom dockerfile you create needs to act as a template. This can look a bit different to how you might have written dockerfiles in the past, since the same template file will need to be used for all services that match the configuration the entrypoint will use a variable which contains the service's filename.

Here are some example dockerfiles:

Expand Down

0 comments on commit b05e3a4

Please sign in to comment.