What I am trying to do
- Package ReactJS app in Docker Container from Windows 11
- Tag Image and Push to AWS ECR
- Use same image on AWS EC2 to Run
Building on Windows 11 with WSL 2
docker buildx ls ✔ ▓▒░
NAME/NODE DRIVER/ENDPOINT STATUS PLATFORMS
desktop-linux protocol not available
default * docker
default default running linux/amd64, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v6
Dockerfile
# FROM --platform=$BUILDPLATFORM node:18-alpine
FROM node:18-alpine
WORKDIR .
COPY package.json ./
COPY package-lock.json ./
RUN npm install --silent
# RUN npm install react-scripts -g --silent
# Slows down the build process copies all
COPY .. ./
# Copy only build folder which is only required in case of reactJS
#COPY build build
RUN npm run build --omit=dev
# Install `serve` to run the application.
RUN npm install --location=global serve
# start app in development mode
CMD ["npm", "start"]
Docker Build CMD
docker buildx build . --tag frontend --platform linux/arm64
Docker Build output
[+] Building 141.0s (13/13) FINISHED
=> [internal] load build definition from Dockerfile 0.2s
=> => transferring dockerfile: 705B 0.0s
=> [internal] load .dockerignore 0.1s
=> => transferring context: 35B 0.0s
=> [internal] load metadata for docker.io/library/node:18-alpine 2.5s
=> [auth] library/node:pull token for registry-1.docker.io 0.0s
=> [internal] load build context 0.1s
=> => transferring context: 56.36kB 0.0s
=> [1/8] FROM docker.io/library/node:18-alpine@sha256:57b98f182ea7253f213f742f1f7bac3f881adc5e40d72f5eafbf2e70bf6f6647 0.0s
=> CACHED [2/8] COPY package.json ./ 0.0s
=> CACHED [3/8] COPY package-lock.json ./ 0.0s
=> CACHED [4/8] RUN npm install --silent 0.0s
=> [5/8] COPY .. ./ 1.6s
=> [6/8] RUN npm run build --omit=dev 129.5s
=> [7/8] RUN npm install --location=global serve 5.1s
=> exporting to image 1.8s
=> => exporting layers 1.7s
=> => writing image sha256:fadcf609c8a50f455383e2a3ee4080c91d976f5b1c7dadec6df3faa0c9bb0e15 0.0s
=> => naming to docker.io/library/frontend
Docker Inspect Output
docker image inspect frontend --format '{{.Os}}/{{.Architecture}}'
linux/arm64
As per logs, I have built a docker image that will support the ARM64 architecture.
As I pushed this image to AWS ECR.
I am Using AWS EC2 t4x2large system which is based on Arm-based AWS Graviton2 processors
uname -m
aarch64
Problem
Docker Running on AWS Server creating the problem.
docker run -it -p 8016:3000 ****amazonaws.com/frontend:latest
exec /usr/local/bin/docker-entrypoint.sh: exec format error
Inspecting the image also shows that it is the same Architecture
docker image inspect ****amazonaws.com/frontend:latest --format '{{.Os}}/{{.Architecture}}'
linux/arm64
But when I am building the same image from the same dockerfile on AWS it is working as expected and the output to that is
docker image inspect frontend:latest --format '{{.Os}}/{{.Architecture}}'
linux/arm64
This problem I am facing only in ReactJS build ...
I used python image to build the arm64 image to run on AWS and it is working fine build was done from windows 11 itself.
I don't know what I am doing wrong. Any help will be appreciated