I’m using a Mac M1 (arm processor) and want to deploy my app containerizing it. I’m able to create the container, but when running npm start
the app throws an error:
Error loading shared library /usr/app/programs/server/npm/node_modules/meteor/accounts-password/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node: Exec format error
This is the script I’m using to create the container, I run it at the root folder of my meteor project:
#!/bin/bash
# Source: https://blog.mvp-space.com/how-to-dockerize-a-meteor-app-with-just-one-script-4bccb26f6ff0
APP_NAME=someappname
APP_DOMAIN=https://www.example.com
APP_PORT=80
SETTINGS_PATH=settings-production.json
METEOR_VERSION=2.7.3
MONGO_URL="mongo url..."
echo "=> Removing /tmp/${APP_NAME}"
rm -rf /tmp/${APP_NAME}
echo "=> Executing Meteor Build..."
meteor build \
--architecture os.linux.x86_64 \
--allow-superuser \
--directory /tmp/${APP_NAME} \
--server=${APP_DOMAIN}/
echo "=> Copying settings file..."
cp ${SETTINGS_PATH} /tmp/${APP_NAME}/bundle/settings.json
echo "=> Moving to /tmp/${APP_NAME}/bundle"
cd /tmp/${APP_NAME}/bundle
# Create package.json
echo "=> Creating package.json..."
cat > package.json <<- "EOF"
{
"name": "app",
"version": "1.0.0",
"scripts": {
"start": "METEOR_SETTINGS=$(cat settings.json) node main.js"
}
}
EOF
# Create the Dockerfile
echo "=> Creating Dockerfile..."
cat > Dockerfile <<EOF
# Pull base image.
FROM mhart/alpine-node:14
# Install build tools to compile native npm modules
RUN apk add --update build-base python
# Create app directory
RUN mkdir -p /usr/app
COPY . /usr/app
RUN cd /usr/app/programs/server && npm install --production
WORKDIR /usr/app
ENV PORT=3000
ENV MONGO_URL=${MONGO_URL}
ENV ROOT_URL=${APP_DOMAIN}/
CMD [ "npm", "start" ]
EXPOSE 3000
EOF
# Build the docker image
echo "=> Building docker image..."
docker stop ${APP_NAME}
docker rm -f ${APP_NAME}
docker rmi -f ${APP_NAME}
# Once everything is out of the way we can build the image
docker buildx build \
--platform linux/amd64 \
-t ${APP_NAME} .
# Start the container
# echo "=> Starting ${APP_NAME} container..."
docker run --rm -it --platform linux/amd64 --entrypoint sh ${APP_NAME}
It seems like:
meteor build \
--architecture os.linux.x86_64 \
is not creating the right bcrypt package for amd64. Is this a bug, am I doing something wrong… or is there a workaround?
Thank you!