Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

To Dockerize a Node.js app for Azure App Service, make the server listen on process.env.PORT, package the app with a Dockerfile whose startup command runs the server in the foreground, push the image to a registry, and configure App Service to use that image. For repeatable releases, automate the build, push, and deployment in GitHub Actions. If the container fails to start, check its logs first, then verify the port, startup command, dependencies, and deployed image.

Choose how Azure will build and run the app

There are two distinct deployment paths. In one, App Service builds an application from deployed files using its build automation. In the other, your workflow builds a custom container image and App Service runs that image. This walkthrough focuses on the custom-container path because it starts with a Dockerfile; the file-deployment route can make sense when you do not need a custom OS or runtime environment.

Decision Deploy app files with App Service build automation Build and deploy a custom container
Who builds the runtime artifact? App Service build automation processes the deployed application files. See Microsoft’s Node.js App Service configuration guide. Your workflow builds an image, pushes it to a registry, and selects that image for deployment. See Microsoft’s GitHub Actions deployment guide.
Custom OS or runtime environment Use this route when the App Service-provided build and runtime are sufficient; the cited guide does not establish that every app can use it. Use a custom image when you need to control the container environment. The exact Dockerfile depends on the app structure and Node.js version.
Dependencies and compiled output Build automation must be configured intentionally if the app requires a build step; otherwise deploy the required runnable files. See Microsoft’s App Service GitHub Actions guidance. Package the runtime dependencies and compiled output in the image, or build them as part of the image process.
Image versioning and rollback There is no container image tag in this route; manage application artifacts through the deployment workflow. Tag images with identifiable versions. Microsoft’s example uses the commit SHA, making it easier to identify which image a deployment uses. A rollback process should redeploy a previously built image tag.
Registry and authentication setup No container registry push is required for the file-deployment route. Configure registry access and Azure authentication for the workflow. Store credentials as repository secrets rather than committing them. See the deployment action documentation.

For either approach, confirm how the app is built and what files App Service will run. The workflow examples below use a custom image, not App Service build automation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Make the Node.js server listen on Azure’s port

Read the listening port from the environment instead of binding only to a hard-coded development port. Microsoft says App Service sets PORT in the Node.js container and forwards incoming requests to that port. See Configure Node.js Apps – Azure App Service.

const port = process.env.PORT || 3000;

app.listen(port, () => {
  console.log(`Server listening on ${port}`);
});

The fallback is useful for local development; on App Service, the environment-provided value takes precedence. A container that listens only on a fixed local port may start successfully yet fail to receive App Service traffic.

For a custom container, the app’s listening port and the hosting target port must agree. Microsoft’s custom-container configuration documentation says App Service supports one exposed HTTP port for a custom container. See Configure a custom container for Azure App Service.

Build an image that actually starts the server

Your Dockerfile must copy the files the production app needs, install or include its runtime dependencies, and finish with a command that launches the server. There is no single correct Dockerfile for every Node app: the Node version, package manager, build output, and directory layout determine the details.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check the final CMD or ENTRYPOINT carefully. The process must run the intended server and stay in the foreground so the container remains alive. Microsoft’s startup troubleshooting guidance for Azure Container Apps states: “Verify that the image’s start command actually starts the intended service.” The principle applies when diagnosing a container start failure, though that page is specifically for Azure Container Apps. See Troubleshoot start failures in Azure Container Apps.

  • Confirm the command references the actual production start script or server entry point.
  • Check that the packages required at runtime are present in the image.
  • Make sure compiled files are copied into the image if the server starts from compiled output.
  • Run the image locally and verify that its server process stays up and listens on the expected port.

Build, push, and deploy the image with GitHub Actions

A deployment workflow needs to build an image, push it to a registry, and configure App Service to run the fully qualified image name. Microsoft’s example uses Azure Container Registry (ACR) and a commit SHA tag. The SHA identifies the image associated with a source revision more precisely than a mutable tag such as latest.

  1. Prepare the app. Ensure the production start script, runtime dependencies, Dockerfile, and port handling are correct. If the app needs compilation, decide where that build happens before proceeding.
  2. Build and tag the image. In the workflow, build from the repository’s Dockerfile and tag the image with a traceable identifier, such as the commit SHA.
  3. Authenticate and push. Log in to the registry using credentials held in repository secrets, then push the tagged image.
  4. Deploy the exact image. Configure the deployment step to use the fully qualified registry image and tag that the build step just pushed.
  5. Verify the running deployment. Check the App Service container configuration and startup logs before changing unrelated settings.

Microsoft documents a GitHub Actions deployment example at Deploy a container to Azure App Service using GitHub Actions. The workflow must keep its build, push, and deployment image names in sync; otherwise App Service can be pointed at an older or nonexistent image.

Handle TypeScript and other compiled apps deliberately

A successful image build does not guarantee that the deployed app contains the files its startup command needs. For TypeScript or another compiled Node.js app deployed using azure/webapps-deploy@v3, Microsoft instructs teams to build in GitHub Actions and deploy the compiled output folder, such as dist/ or build/. See Deploy by Using GitHub Actions – Azure App Service.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

With a custom container, make an explicit choice: compile before building the image and copy the output into it, or compile during the Docker image build. With file deployment, ensure the workflow deploys the compiled directory, or deliberately configure App Service build automation. Do not assume that source files will be compiled automatically in every deployment path.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Diagnose the three common failure categories

1. Port mismatch: the container runs but traffic does not reach the app

Compare the port the server actually binds to with the port App Service expects for the custom container. Confirm that the app reads process.env.PORT and that the custom-container target-port configuration matches. App Service custom containers support one exposed HTTP port, so do not assume it will route to whichever port the app happens to use. Start with the Node.js port guidance and custom-container configuration.

2. Bad startup command or early exit: the container starts and then stops

Inspect the Dockerfile’s CMD and ENTRYPOINT, then check whether the referenced script exists and whether the required packages are installed. An application exception can also terminate the process. The startup command needs to launch the intended server in the foreground, not a short-lived setup task or a development command that is absent from the production image. Microsoft’s container start-failure guidance recommends verifying that the image start command launches the intended service.

3. Wrong artifact or image: deployment succeeds but the expected app is missing

For a compiled app, verify that the output directory was created and included in the deployed artifact or image. For a custom container, check that the workflow pushed the intended image tag and that the deployment step selects the same fully qualified image. A commit-SHA tag helps distinguish the artifact built from one revision from another. See the container deployment workflow guide and the compiled-output guidance.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Turn on logs and inspect before changing settings

Use App Service container logging and deployment logs to identify the first actionable error. Microsoft documents the Azure CLI commands az webapp log config for configuring logging and az webapp log tail for viewing log output. See custom-container configuration and logging and the deployment guidance.

az webapp log config --name <app-name> --resource-group <resource-group> --docker-container-logging filesystem
az webapp log tail --name <app-name> --resource-group <resource-group>

Use the actual App Service name and resource group in place of the angle-bracketed values. Read the startup output for a missing module, a failed start script, an application exception, or a message indicating that the app is listening on the wrong port. Also check deployment output when the logs suggest the wrong image was selected. Change one diagnosed cause at a time, then rebuild or redeploy and inspect the new output.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.