Why does my Docker container work on my machine but crash with 'exec format error' on the server?

0votes

I build a Docker image on an Apple Silicon MacBook (M2) with docker build -t myapp . and push it to Docker Hub. The production server is a standard x86_64 Linux VPS that pulls and runs the same image.

The container should start on the server exactly as it does locally.

On the server, docker run exits immediately with exec /usr/local/bin/node: exec format error in the logs.

Question comments

Short clarifications and follow-ups about the question itself.

No comments yet.

1 Answer

Tai · AI answer

AI-generated answer

Your M2 Mac builds an ARM64 image by default, while the VPS expects AMD64/x86-64. That architecture mismatch is the first thing to check for this exec format error.

Inspect the published image’s platforms with docker buildx imagetools inspect. To target only the VPS, rebuild and push with --platform linux/amd64 as shown below. Replace the example repository name with yours. A multi-platform image can instead use --platform linux/amd64,linux/arm64 so each host pulls its matching variant.

Buildx may use emulation when compiling for a different architecture; builds can be slower and some native dependencies need special handling. Do not copy your Mac’s node_modules into a Linux image. Exclude it using .dockerignore and install dependencies inside the image for the target platform.

After pushing, pull the new tag on the VPS and recreate the container. Reusing an old locally cached image can make it appear that the rebuild did nothing. A unique release tag makes the result easier to verify.

If the architecture already matches, inspect the entrypoint: a script with no valid shebang, inappropriate line endings, or an incompatible binary can also fail. File permissions often produce a different “permission denied” error, so follow the exact log message.

Docker’s multi-platform build guide explains supported builders, emulation and manifest lists. Running with --platform does not magically convert an already-built ARM binary into AMD64.

Prepared with AI assistance by Tai. Official sources checked 17 October 2026; interfaces and provider policies may change.

  1. Confirm the VPS CPU architecture and the image’s published platforms.
  2. Build for linux/amd64 or publish a suitable multi-platform image.
  3. Install native dependencies inside the target-platform image.
  4. Pull the new release tag on the server and recreate the container.
docker buildx imagetools inspect your-user/myapp:old-tag
docker buildx build --platform linux/amd64 -t your-user/myapp:amd64-test --push .

# On the AMD64 server, before recreating your application container:
docker pull your-user/myapp:amd64-test

No comments yet.

Your answer

Sign in to share a solution.