Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error occurs on first run if NPM is not allready installed #10

Open
Marc-Gee opened this issue Jul 19, 2023 · 5 comments
Open

Error occurs on first run if NPM is not allready installed #10

Marc-Gee opened this issue Jul 19, 2023 · 5 comments

Comments

@Marc-Gee
Copy link

Trying docker for windows for my 1st time!
Windows 11 and VS code both current versions.

Running the docker build -t welcome-to-docker . command returns an error " ERROR: failed to solve: process "/bin/sh -c npm install....."
This error persisted because my WSL2 machine , or my host machine, (I am not sure which ) did not have NPM installed already.
ie trying

This was solved via running 'sudo apt install npm' in the WSL2 Ubuntu VM, and then running the welcome to docker build script again.
The container then built successfully.

@Stitch-Taotao
Copy link

Stitch-Taotao commented Mar 1, 2024

Same issue when run cmd in powershell.
Following docker desktop leanning center instruction , error occur when build step:

Logs of **docker build -t welcome-to-docker . **
docker build -t welcome-to-docker .                                                  
2024/03/01 14:11:12 http2: server: error reading preface from client //./pipe/docker_engine: file has already been closed
[+] Building 3.3s (11/11) FINISHED                                                                                                                                                                                   docker:default
 => [internal] load build definition from Dockerfile                                                                                                                                                                           0.0s
 => => transferring dockerfile: 669B                                                                                                                                                                                           0.0s 
 => [internal] load metadata for docker.io/library/node:18-alpine                                                                                                                                                              3.0s 
 => [auth] library/node:pull token for registry-1.docker.io                                                                                                                                                                    0.0s
 => [internal] load .dockerignore                                                                                                                                                                                              0.0s
 => => transferring context: 52B                                                                                                                                                                                               0.0s 
 => [1/6] FROM docker.io/library/node:18-alpine@sha256:ca9f6cb0466f9638e59e0c249d335a07c867cd50c429b5c7830dda1bed584649                                                                                                        0.0s 
 => [internal] load build context                                                                                                                                                                                              0.0s 
 => => transferring context: 393B                                                                                                                                                                                              0.0s 
 => CACHED [2/6] WORKDIR /app                                                                                                                                                                                                  0.0s 
 => CACHED [3/6] COPY package*.json ./                                                                                                                                                                                         0.0s 
 => CACHED [4/6] COPY ./src ./src                                                                                                                                                                                              0.0s
 => CACHED [5/6] COPY ./public ./public                                                                                                                                                                                        0.0s 
 => ERROR [6/6] RUN npm install     && npm install -g serve     && npm run build     && rm -fr node_modules                                                                                                                    0.3s 
------
 > [6/6] RUN npm install     && npm install -g serve     && npm run build     && rm -fr node_modules:
0.253 exec /bin/sh: exec format error
------
Dockerfile:15
--------------------
  14 |     # Install node packages, install serve, build the app, and remove dependencies at the end
  15 | >>> RUN npm install \
  16 | >>>     && npm install -g serve \
  17 | >>>     && npm run build \
  18 | >>>     && rm -fr node_modules
  19 |
--------------------
ERROR: failed to solve: process "/bin/sh -c npm install     && npm install -g serve     && npm run build     && rm -fr node_modules" did not complete successfully: exit code: 1

View build details: docker-desktop://dashboard/build/default/default/36fq292mclyizqosxrq2xj1lr

@varuneranki
Copy link

I faced the same issue under Windows. Using the same tutorial. Solution: Start cmd as administrator and it would work. If Linux, then Terminal requires sudo docker build -t welcome-to-docker . and the password for the user.

@Vacman
Copy link

Vacman commented Mar 18, 2024

Yeah - I still can't get it running as well...

docker build -t welcome-to-docker .
2024/03/18 15:57:41 http2: server: error reading preface from client //./pipe/docker_engine: file has already been closed
[+] Building 205.0s (10/10) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 669B 0.0s
=> [internal] load metadata for docker.io/library/node:18-alpine 1.1s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 52B 0.0s
=> [1/6] FROM docker.io/library/node:18-alpine@sha256:c7620fdecfefb96813da62519897808775230386f4c8482e972e37b8b18cb460 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 393B 0.0s
=> CACHED [2/6] WORKDIR /app 0.0s
=> CACHED [3/6] COPY package*.json ./ 0.0s
=> CACHED [4/6] COPY ./src ./src 0.0s
=> CACHED [5/6] COPY ./public ./public 0.0s
=> ERROR [6/6] RUN npm install && npm install -g serve && npm run build && rm -fr node_modules 203.9s

[6/6] RUN npm install && npm install -g serve && npm run build && rm -fr node_modules:
4.687 npm WARN deprecated [email protected]: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
4.708 npm WARN deprecated [email protected]: Please use @jridgewell/sourcemap-codec instead
4.716 npm WARN deprecated [email protected]: Use your platform's native performance.now() and performance.timeOrigin.
5.333 npm WARN deprecated [email protected]: This SVGO version is no longer supported. Upgrade to v2.x.x.
34.92 npm WARN deprecated [email protected]: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-terser
203.8 npm notice
203.8 npm notice New minor version of npm available! 10.2.4 -> 10.5.0
203.8 npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.5.0
203.8 npm notice Run npm install -g [email protected] to update!
203.8 npm notice
203.8 npm ERR! code ECONNRESET
203.8 npm ERR! errno ECONNRESET
203.8 npm ERR! network request to https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz failed, reason: Client network socket disconnected before secure TLS connection was established
203.8 npm ERR! network This is a problem related to network connectivity.
203.8 npm ERR! network In most cases you are behind a proxy or have bad network settings.
203.8 npm ERR! network
203.8 npm ERR! network If you are behind a proxy, please make sure that the
203.8 npm ERR! network 'proxy' config is set properly. See: 'npm help config'
203.8
203.8 npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2024-03-18T22_57_43_298Z-debug-0.log


Dockerfile:15

14 | # Install node packages, install serve, build the app, and remove dependencies at the end
15 | >>> RUN npm install
16 | >>> && npm install -g serve
17 | >>> && npm run build
18 | >>> && rm -fr node_modules
19 |

ERROR: failed to solve: process "/bin/sh -c npm install && npm install -g serve && npm run build && rm -fr node_modules" did not complete successfully: exit code: 1

@Hellal1997
Copy link

Stage 1: Build the React application

FROM node:8.15.1-alpine as build-stage

Set the working directory in the container

WORKDIR /usr/src/app

Copy package.json and package-lock.json

COPY package*.json ./

Install dependencies

RUN npm --verbose install

Copy the rest of the application code

COPY . .

Build the React application

RUN npm run build
RUN npm install --force

Stage 2: Serve the React application using a lightweight web server

FROM nginx:alpine

Copy the build artifacts from the build stage

#COPY --from=build /app/build /usr/share/nginx/index.html

Expose port 80 to access the application

EXPOSE 80

Start Nginx

CMD ["nginx", "-g", "daemon off;"]

@senfish
Copy link

senfish commented Nov 25, 2024

Stage 1: Build the React application

FROM node:8.15.1-alpine as build-stage

Set the working directory in the container

WORKDIR /usr/src/app

Copy package.json and package-lock.json

COPY package*.json ./

Install dependencies

RUN npm --verbose install

Copy the rest of the application code

COPY . .

Build the React application

RUN npm run build RUN npm install --force

Stage 2: Serve the React application using a lightweight web server

FROM nginx:alpine

Copy the build artifacts from the build stage

#COPY --from=build /app/build /usr/share/nginx/index.html

Expose port 80 to access the application

EXPOSE 80

Start Nginx

CMD ["nginx", "-g", "daemon off;"]

Why did you use COPY twice instead of using COPY . . for the first time?

I tried to use COPY . . ,but got an error。

Image
This is my Dockerfile.

FROM node:18-alpine3.14 as build-stage

WORKDIR /app
COPY . .
RUN npm config set registry https://registry.npmmirror.com/
RUN npm install
RUN npm run build

When I use COPY . . , won't the package.json file be copied over?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants