getting-started icon indicating copy to clipboard operation
getting-started copied to clipboard

Using Bind Mounts part of tutorial on Macbook with M1Pro

Open bcromijn opened this issue 4 years ago • 9 comments

While running the command:

docker run -dp 3000:3000 \
    -w /app -v "$(pwd):/app" \
    node:12-alpine \
    sh -c "yarn install && yarn run dev"

the container starts and stops immediately with exit code 1. When I look in the logs in Docker Desktop I see the following.

yarn install v1.22.15
[1/4] Resolving packages...
[2/4] Fetching packages...
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning Resolution field "[email protected]" is incompatible with requested version "ansi-regex@^2.0.0"
warning Resolution field "[email protected]" is incompatible with requested version "ansi-regex@^3.0.0"
warning sqlite3 > node-gyp > [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
warning sqlite3 > node-gyp > [email protected]: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.
warning sqlite3 > node-gyp > request > [email protected]: this library is no longer supported
warning sqlite3 > node-gyp > request > [email protected]: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
[4/4] Building fresh packages...
error /app/node_modules/sqlite3: Command failed.
Exit code: 1
Command: node-pre-gyp install --fallback-to-build
Arguments: 
Directory: /app/node_modules/sqlite3
Output:
node-pre-gyp info it worked if it ends with ok
node-pre-gyp info using [email protected]
node-pre-gyp info using [email protected] | linux | arm64
node-pre-gyp WARN Using request for node-pre-gyp https download 
node-pre-gyp info check checked for "/app/node_modules/sqlite3/lib/binding/napi-v3-linux-arm64/node_sqlite3.node" (not found)
node-pre-gyp http GET https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v5.0.2/napi-v3-linux-arm64.tar.gz
node-pre-gyp http 403 https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v5.0.2/napi-v3-linux-arm64.tar.gz
node-pre-gyp WARN Tried to download(403): https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v5.0.2/napi-v3-linux-arm64.tar.gz 
node-pre-gyp WARN Pre-built binaries not found for [email protected] and [email protected] (node-v72 ABI, musl) (falling back to source compile with node-gyp) 
node-pre-gyp http 403 status code downloading tarball https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v5.0.2/napi-v3-linux-arm64.tar.gz 
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | linux | arm64
gyp info ok 
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | linux | arm64
gyp ERR! configure error 
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
gyp ERR! stack     at PythonFinder.failNoPython (/app/node_modules/node-gyp/lib/configure.js:484:19)
gyp ERR! stack     at PythonFinder.<anonymous> (/app/node_modules/node-gyp/lib/configure.js:406:16)
gyp ERR! stack     at F (/app/node_modules/which/which.js:68:16)
gyp ERR! stack     at E (/app/node_modules/which/which.js:80:29)
gyp ERR! stack     at /app/node_modules/which/which.js:89:16
gyp ERR! stack     at /app/node_modules/isexe/index.js:42:5
gyp ERR! stack     at /app/node_modules/isexe/mode.js:8:5
gyp ERR! stack     at FSReqCallback.oncomplete (fs.js:168:21)
gyp ERR! System Linux 5.10.47-linuxkit
gyp ERR! command "/usr/local/bin/node" "/app/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/app/node_modules/sqlite3/lib/binding/napi-v3-linux-arm64/node_sqlite3.node" "--module_name=node_sqlite3" "--module_path=/app/node_modules/sqlite3/lib/binding/napi-v3-linux-arm64" "--napi_version=8" "--node_abi_napi=napi" "--napi_build_version=3" "--node_napi_label=napi-v3"
gyp ERR! cwd /app/node_modules/sqlite3
gyp ERR! node -v v12.22.7
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
node-pre-gyp ERR! build error 
node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /app/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/app/node_modules/sqlite3/lib/binding/napi-v3-linux-arm64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/app/node_modules/sqlite3/lib/binding/napi-v3-linux-arm64 --napi_version=8 --node_abi_napi=napi --napi_build_version=3 --node_napi_label=napi-v3' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/app/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:314:20)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:1022:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
node-pre-gyp ERR! System Linux 5.10.47-linuxkit
node-pre-gyp ERR! command "/usr/local/bin/node" "/app/node_modules/sqlite3/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /app/node_modules/sqlite3
node-pre-gyp ERR! node -v v12.22.7
node-pre-gyp ERR! node-pre-gyp -v v0.11.0
node-pre-gyp ERR! not ok 
Failed to execute '/usr/local/bin/node /app/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/app/node_modules/sqlite3/lib/binding/napi-v3-linux-arm64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/app/node_modules/sqlite3/lib/binding/napi-v3-linux-arm64 --napi_version=8 --node_abi_napi=napi --napi_build_version=3 --node_napi_label=napi-v3' (1)
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

Maybe it's a good idea t make a separate section or code snippets for the new Mac processors?

bcromijn avatar Nov 15 '21 17:11 bcromijn

I have the same problem and have no docker experience, but my laptop is windows10. Is there any difference between M1 and Windows commands?

Leo-zryan avatar Nov 16 '21 06:11 Leo-zryan

See #124

What worked for me on a MacbookPro M1 was:

docker run -dp 3000:3000 \
    -w /app -v "$(pwd):/app" \
    node:12-alpine \
    sh -c "apk --no-cache --virtual build-dependencies add python2 make g++ && yarn install && yarn run dev"

chriso0710 avatar Nov 21 '21 15:11 chriso0710

Thanks a lot @chriso0710 ! This worked and helped me to continue the tutorial.

nalla12 avatar Nov 21 '21 20:11 nalla12

This worked for me as well @chriso0710. Thanks a lot!

bcromijn avatar Nov 22 '21 08:11 bcromijn

Hi there, I work in a Macbook with an M1 processor, I followed the documentation but didn't work for me, so I tried to change python3 to python2 when I try to build the image, it worked, I don-t know why, if anybody could help to understand I'd appreciated it.

# syntax=docker/dockerfile:1
FROM node:12-alpine
RUN apk add --no-cache python2 g++ make
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "src/index.js"]

KishinNext avatar Nov 25 '21 01:11 KishinNext

Hi there, I work in a Macbook with an M1 processor, I followed the documentation but didn't work for me, so I tried to change python3 to python2 when I try to build the image, it worked, I don-t know why, if anybody could help to understand I'd appreciated it.

# syntax=docker/dockerfile:1
FROM node:12-alpine
RUN apk add --no-cache python2 g++ make
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "src/index.js"]

@KishinNext Ah nice thanks that did the trick! I think I get it now. python2 is reachable via python in e.g. the terminal but python3 is only reachable via python3. So if we would install python3, yarn naturally can't find the program python as we have the program python3.

visuallization avatar Nov 25 '21 10:11 visuallization

Thanks much @chriso0710 ! It worked for me!

gill876 avatar Jan 15 '22 02:01 gill876

Maybe it's a good idea t make a separate section or code snippets for the new Mac processors?

I didn't see that the issue is closed yet and I found this issue while googling the answer... so I hope this will help someone else in the future. (and also ID a place in the tutorial where documentation needs to be updated)

Separate of this specific issue - I found that the documentation in the tutorial under "Image Building Best Practices" is missing code for M1 Macs... The original dockerfile code listed below runs into the same error that is mentioned by OP:

FROM node:12-alpine 
WORKDIR /app 
COPY package.json yarn.lock ./ 
RUN yarn install --production 
COPY . . CMD ["node", "src/index.js"]

The following fixed the dockerfile when I was working through the code, it's mentioned back in "Our Application - Getting Started" but isn't mentioned again anywhere else.

FROM node:12-alpine
# Adding build tools to make yarn install work on Apple silicon / arm64 machines
RUN apk add --no-cache python2 g++ make
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --production
COPY . .
CMD ["node", "src/index.js"]

michaeltkuo avatar Apr 04 '22 22:04 michaeltkuo

Slightly clearer solution here

Slightly more context

ColemanDunn avatar Apr 26 '22 19:04 ColemanDunn