local Command - Medusa Cloud CLI Reference

In this guide, you'll learn how to reproduce a Cloud build on your machine using the CLI. This is useful for debugging build failures without pushing changes and waiting for a Cloud deployment.

Note: This command is available starting Medusa mcloud CLI v0.1.10. Make sure to update your CLI to the latest version if you don't see this command.

local build#

Run a Cloud build on your machine, mirroring how Cloud builds your project. Run the command from within your project.

By default, the command builds the backend. Pass --type storefront to build the storefront instead.

The CLI infers the project's root path and environment variables from the linked Cloud project and environment, so it reproduces the Cloud build as closely as possible.

The command streams the build progress to your terminal. It prepares a build directory, generates a Dockerfile that mirrors the Cloud build, then builds the Docker image. The output looks similar to the following:

Terminal
Running local backend build in /tmp/mcloud-local-build/myuser-my-repo/backendGenerating Dockerfile#1 [internal] load build definition from Dockerfile#1 transferring dockerfile: 2.34kB done#1 DONE 0.0s
# ... Docker build output for each layer ...
#24 exporting to image#24 exporting layers done#24 writing image sha256:0a1b2c3d4e5f done#24 naming to docker.io/library/my-repo:cloud-local-build-a1b2c3d done#24 DONE 1.2s

If the build succeeds, the resulting image is tagged <repository-name>:cloud-local-build-<commit-hash>. If it fails, the command exits with the failing command's error so you can debug it the same way you would a Cloud build.

Note: Before the build starts, the CLI may print warnings if your installed CLI version is outdated, or if the current repository or branch doesn't match the linked Cloud project and environment. These are warnings only and don't stop the build.If your repository does not have a remote origin configured, the CLI falls back to using the local folder name as the repository name.

Override Environment Variables#

To build with a local .env file instead of the Cloud environment's variables, or to override specific variables, use --env-file or --var:

Terminal
mcloud local build \  --env-file .env \  -v NODE_ENV=production

Build the Storefront#

To build the storefront instead of the backend, pass --type storefront (or -t storefront). The CLI infers the storefront's path from the linked Cloud project, or you can set it with --storefront-path:

Terminal
mcloud local build \  --type storefront \  --storefront-path apps/storefront

The command builds the storefront in a Docker container and writes the build output to a local directory. When it finishes, it prints the output path:

Terminal
Running local storefront build in /tmp/mcloud-local-build/myuser-my-repo/storefront
# ... Docker build output ...
Storefront build complete. Output: /tmp/mcloud-local-build/myuser-my-repo/storefront/output

Options#

Option

Description

Required

Default

-o <id>, --organization <id>

The ID of the organization that the project belongs to.

No

Falls back to the organization in the active context, if set.

-p <id-or-handle>, --project <id-or-handle>

The ID or handle of the project to build.

No

Falls back to the project in the active context, if set.

-e <handle>, --environment <handle>

The handle of the environment whose variables are used for the build.

No

Falls back to the environment in the active context, if set.

-t <type>, --type <type>

The build type to run. Accepts backend or storefront.

No

backend

--root-path <path>

The root path of the Medusa project relative to the repository root. Used for backend builds. Inferred from the Cloud project if not specified, or . if a Cloud project isn't found.

No

Inferred

--storefront-path <path>

The path to the storefront project relative to the repository root. Used for storefront builds. Inferred from the Cloud project if not specified.

No

Inferred

--env-file <path>

Path to a .env file to use for the build. If not specified, environment variables are inferred from the Cloud environment.

No

Inferred

-v <var>, --var <var>

An environment variable to override for the build, in KEY=VALUE format. Pass it multiple times to override more than one variable.

No

-

--docker-cache

Enable the Docker build cache. Disabled by default so that environment variable changes always invalidate the cache.

No

false

Was this guide helpful?
Ask Bloom
For assistance in your development, use Claude Code Plugins or Medusa MCP server in Cursor, VSCode, etc...FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break