educative.io

Problems with macOS + Docker Desktop

I am trying to get this to work on my laptop (macOS Monterey). Here is my current Dockerfile:

FROM node:11-alpine

WORKDIR /scripts

COPY compute,js .

CMD pwd; ls -lh; cat compute.js


After getting errors I read that specifying a WORKDIR could help. The output when this is built and run:

% docker run --rm jsimage
/scripts
total 4
-rw-r–r-- 1 root root 129 Nov 9 15:19 compute,js
cat: can’t open ‘compute.js’: No such file or directory

So the pwd and ls commands work fine, but not cat. Something is strange about the copied compute.js file (which is fine on the macOS disk.)

And of course using the node command (instead of cat) just tells me that it can’t find the compute.js file. Any suggestions?


Type your question above this line.

Course: https://www.educative.io/collection/10370001/4646285862764544
Lesson: https://www.educative.io/collection/page/10370001/4646285862764544/6751132682551296

Hi @Jonathan_Smith

I followed the steps given in the lesson (Exercise Solution) and it is working fine for me.
I got the output on the screen with using “node” command.

Using “cat” command with JS file will not show you anything on terminal as “cat” is a standard Unix utility that reads files sequentially, writing them to standard output.

If you got error while using “node” command, it must be related to path. Your terminal may not be at that directory where Dockerfile and compute.js.

Recheck it one more time and make sure that Dockerfile and compute.js are in a same directory and you using node compute.js command from that directory.