Introduction
The Nx Tools Container plugin provides comprehensive executors and generators for building and managing OCI-compliant container images within Nx workspaces.
The @nx-tools/nx-container plugin streamlines container image workflows in Nx monorepos by providing a unified interface for multiple container build engines and automated image management capabilities.
Key Features
- Multi-Engine Support: Build container images using your preferred container engine:
- Docker Buildx with Moby BuildKit for advanced build features
- Podman for rootless and daemonless container builds
- Automated Image Management: Intelligent tag generation and OCI Image Format Specification compliant labeling
- Project Scaffolding: Code generators to quickly configure container builds for your applications
Getting Started
Installation
To add the @nx-tools/nx-container plugin to your Nx workspace, run the following command:
npx nx add @nx-tools/nx-containerThis command will:
- Install the plugin package
- Configure the plugin in your
nx.jsonfile - Set up default configurations for your workspace
Task Inference
The plugin automatically detects projects suitable for containerization and adds a container task to any project containing a Dockerfile. This intelligent inference eliminates the need for manual task configuration in most cases.
Viewing Inferred Tasks
To inspect the automatically inferred tasks for any project:
- Using Nx Console: Open the project details view for comprehensive task visualization
- Using CLI: Execute
nx show project <project-name>to display project configuration and available tasks
Configuration
Plugin Configuration
Configure the @nx-tools/nx-container plugin in your workspace's nx.json file within the plugins array:
{
"plugins": [
{
"plugin": "@nx-tools/nx-container",
"options": {
"defaultEngine": "docker",
"defaultRegistry": "docker.io"
}
}
]
}Alternative Engine Configuration
You can customize the default build engine and registry to match your infrastructure requirements:
{
"plugins": [
{
"plugin": "@nx-tools/nx-container",
"options": {
"defaultEngine": "podman",
"defaultRegistry": "ghcr.io"
}
}
]
}Supported Engines:
docker(default) - Standard Docker builds with BuildKitpodman- Rootless container builds
Common Registries:
docker.io- Docker Hub (default)ghcr.io- GitHub Container Registrygcr.io- Google Container Registry- Custom registry URLs
Build your application
nx container appNameTo use a different engine, you need to update the options.engine property of your project target or use the INPUT_ENGINE environment variable. All possible values are docker (the default) and podman
For more details about all available options, please refer to the build executor documentation.
Last updated on