Skip to content

The Nx Plugin for Docker contains executors and utilities for building and publishing docker images within an Nx workspace. Using the @nx/docker Inference Plugin, Nx will automatically detect Dockerfile's in your workspace and provide a docker:build and docker:run target for each. It will also provide a nx-release-publish target for publishing docker images to a registry.

In any Nx workspace, you can install @nx/docker by running the following command:

Terminal window
nx add @nx/docker

This will install the correct version of @nx/docker to match the version of Nx you are using.

The @nx/docker plugin will create a task for any project that has a Dockerfile present. It will infer the following tasks:

  • docker:build
  • docker:run
  • nx-release-publish

To view inferred tasks for a project, open the project details view in Nx Console or run nx show project my-project in the command line.

The @nx/docker plugin is configured in the plugins array in nx.json.

nx.json
{
"plugins": [
{
"plugin": "@nx/docker",
"options": {
"buildTarget": "docker:build",
"runTarget": "docker:run"
}
}
]
}

The buildTarget and runTarget options control the names of the inferred Docker tasks. The default names are docker:build and docker:run.

The @nx/docker plugin provides a nx-release-publish target for publishing docker images to a registry. Nx Release was also updated to support versioning docker images, generating changelogs, and publishing docker images to a registry through a single command.

You can learn more about how to manage releases for Docker Images in the Release Docker Images guide.