Cannot find "concurrently" running a Docker Image - docker

I am trying to create and run a Docker image of my Angular application. It works perfectly fine locally however I am having problems when it is coming to the docker run command.
My Dockerfile is:
FROM node:current
#FROM node:current-slim
#FROM node:12.13.1-alpine
WORKDIR /usr/src/app
COPY package.json .
COPY proxy.conf.json .
RUN npm install
EXPOSE 4200
CMD [ "npm", "run", "dev" ]
In my package.json the scripts are:
"dev": "concurrently \"npm start\" \"ng serve --proxy-config proxy.conf.json\""
and the two Docker commands I am running are:
docker build --tag fuel-consumption-front:0.0.0 .
docker run --publish 8000:4200 --detach --name fuel fuel-consumption-front:0.0.0
The Docker logs are saying (or this is the output on my desktop Docker application for this):
> fuel-consumption-front#0.0.0 dev /usr/src/app
> concurrently "npm start" "ng serve --proxy-config proxy.conf.json"
sh: 1: concurrently: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! fuel-consumption-front#0.0.0 dev: `concurrently "npm start" "ng serve --proxy-config proxy.conf.json"`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the fuel-consumption-front#0.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-03-25T15_30_19_063Z-debug.log
It is the first line that is making me think this is something to do with concurrently not being able to be run
I have tried different node images (commented out in the Dockerfile) and also npm insall -g within the Dockerfile. There is not an entry for concurrentrly in the package.json file either. All different methods are throwing up the same error
I am pretty new with Docker and was using the example from the Docker pages as a template. Their example worked perfectly fine when doing this.

I had more of a play with this after leaving it for a while. Turned out I didn't save my Dockerfile when I added npm install concurrently. Now the Dockerfile reads (with a few more tweaks):
FROM node:current-slim
WORKDIR /usr/src/app
COPY package.json .
COPY proxy.conf.json .
RUN npm install
RUN npm install concurrently
COPY . .
EXPOSE 4200
CMD [ "npm", "run", "dev" ]
Now onto the next issue....need to make the image smaller and it says it compiles fine in the logs but can't connect on localhost:8000 (another problem for another day!)

Related

Could not find a production build in the '/app/.next' directory. Try building your app with 'next build' before starting the production server

Getting their error while running the next.js app image
:
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
Error: Could not find a production build in the '/app/.next' directory. Try building your app with 'next build' before starting the production server. https://nextjs.org/docs/messages/production-start-no-build-id
at NextNodeServer.getBuildId (/app/node_modules/next/dist/server/next-server.js:137:23)
at new Server (/app/node_modules/next/dist/server/base-server.js:93:29)
at new NextNodeServer (/app/node_modules/next/dist/server/next-server.js:86:9)
at NextServer.createServer (/app/node_modules/next/dist/server/next.js:109:16)
at async /app/node_modules/next/dist/server/next.js:121:31
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! anubis-aio#0.1.0 start: next start
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the anubis-aio#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-05-11T12_32_58_222Z-debug.log
Dockerfile:
FROM node:14-alpine AS deps
WORKDIR /app
COPY package.json ./
RUN npm install
COPY . .
FROM node:14-alpine AS builder
WORKDIR /app
COPY --from=deps /app ./
RUN npm build
FROM node:14-alpine AS runner
WORKDIR /app
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next ./.next
RUN npm install next
EXPOSE 3000
CMD ["npm","run","start"]
Do I need to add .next in dockerignore? doing so gives me an error while building the image
The below command solved my error
npm run build
One needs to build the solution before you can start it.
Therefore add the build step immediately before the start command:
…
EXPOSE 3000
CMD ["npm","run","build"]
CMD ["npm","run","start"]
This command solve your problem
npm install

Input/Output Error on Create-React-App in Docker

I'm trying to dockerize my create-react-app development environment and preserving hot reloads. According to most guides (and this guy), the most direct way is docker run -p 3000:3000 -v "$(pwd):/var/www" -w "/var/www" node npm start in the project folder.
However, I'm getting this error instead:
$ docker run -p 3000:3000 -v "$(pwd):/var/www" -w "/var/www" node npm start
> my-app#0.1.0 start /var/www
> react-scripts start
sh: 1: react-scripts: Input/output error
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! my-app#0.1.0 start: `react-scripts start`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the my-app#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-04-02T06_55_22_257Z-debug.log
I'm running on Windows. I believe mounting the volume might have some permission issues leading to the input/output error, but testing various settings didn't work out. I'm honestly stumped. All I want is to run my app in Docker with hot reload for development.
As it turns out, setting up create-react-app in docker takes a little more work.
The primary issue is that mounted volumes are not available in the build step, so when node npm start runs the mounted project files technically don't exist yet.
As such, you need to copy over and install the project first to let it run the first time before the volume mounts. Hot reloading works normally afterwards.
Here's my final working setup:
docker-compose.yml:
create-react-app:
build:
context: create-react-app
ports:
- 3000:3000
environment:
- NODE_PATH=/node_modules
- CHOKIDAR_USEPOLLING=true
volumes:
- ./create-react-app:/create-react-app
Dockerfile:
FROM node:alpine
# Extend PATH
ENV PATH=$PATH:/node_modules/.bin
# Set working directory
WORKDIR /client
# Copy project files for build
ADD . .
# Install dependencies
RUN npm install
# Run create-react-app server
CMD ["npm", "run", "start"]

Could not find a required file

I'm trying to run docker container with create-react-app App. App works fine and here's how my dockerfile looks like.
# base image
FROM node:12.2.0-alpine
# set working directory
WORKDIR ./
# add `//node_modules/.bin` to $PATH
ENV PATH ./node_modules/.bin:$PATH
# install and cache dependencies
COPY package.json ./package.json
COPY ./build/* ./public/
RUN npm install --silent
RUN npm install react-scripts#3.0.1 -g
# start
CMD ["npm", "start"]
When I run docker im getting error
> my-app#0.1.0 start /
> react-scripts start
Could not find a required file.
Name: index.js
Searched in: /src
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-app#0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-app#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2019-07-14T08_29_30_761Z-debug.log
has anybody have any idea?
npm start is for webpack - which serves you as the dev server. you are still using directly the src files, not the minified build (dist), which will only be used on production.
#Dockerfile.dev:
# base image
FROM node:12.2.0-alpine
# set working directory
WORKDIR ./
# add `//node_modules/.bin` to $PATH
ENV PATH ./node_modules/.bin:$PATH
COPY package.json ./package.json
#use the minified build file for production, not now - npm start is for development.
#COPY ./build/* ./public/
#install dependencies:
RUN npm install --silent
RUN npm install react-scripts#3.0.1 -g
#copy your project files: (also bad for development, use volume(https://docs.docker.com/storage/volumes/) instead)
COPY . .
# start
CMD ["npm", "start"]
(This builds on #EfratLevitan's answer, but is a little more production-oriented. Their answer will be better if you want to use Docker as a core part of your development flow.)
If you have a working Webpack setup already, its output is static files that can be served up by any Web server. Once you've successfully run npm run build, you can use anything to serve the resulting build directory – serve it as static content from something like a Flask application, put it in a cloud service like Amazon S3 that can serve it for you, directly host it yourself. Any of the techniques described on the CRA Deployment page will work just fine in conjunction with a Docker-based backend.
If you'd like to serve this yourself via Docker, you don't need Node to serve the build directory, so a plain Web server like nginx will work fine. The two examples from the image description work for you here:
# Just use the image and inject the content as data
docker run -v $PWD/build:/usr/share/nginx/html -p 80:80 nginx
# Build an image with the content "baked in"
cat >Dockerfile <<EOF
FROM nginx
COPY ./build /usr/share/nginx/html
EOF
# Run it
docker build -t me/nginx .
docker run -p 80:80 me/nginx
The all-Docker equivalent to this is to use a multi-stage build to run the Webpack build inside Docker, then copy it out to a production Web server image.
FROM node:12.2.0-alpine AS build
WORKDIR /app
COPY package.json yarn.lock .
RUN npm install --silent
RUN npm install react-scripts#3.0.1 -g
COPY . .
RUN npm run build
FROM nginx
COPY --from=build /app/build /usr/share/nginx/html
In this model you'd develop your front-end code locally. (The Webpack/CRA stack has pretty minimal host dependencies, and since the application runs in the user's browser, it can't depend on Docker-specific networking features.) You'd only build this Dockerfile once you wanted to run an end-to-end test with all of the parts running together before you actually pushed out to production.

Maximum call stack size exceeded npm install by Docker container

I'm trying to npm install by Docker container:
This is a DockerFile:
# default /var/www/html (mapped to .../code folder with projects)
FROM node
WORKDIR /work
# Additional tools (ng, gulp, bower)
RUN npm install -g #angular/cli bower gulp grunt
CMD while true; do sleep 10000; done
EXPOSE 3002 3003 3004
I run and map it with this command:
docker run -d --name node-cmd -p 3002:3002 -p 3003:3003 -p 3004:3004 -v
/m/dockerlogs/node-cmd/logs:/root/.npm/_logs -v /m/projekty:/work node-cmd
I log in to this container with:
docker exec -it node-cmd bash -c "cd /code; bash"
After I run npm install (https://github.com/gdi2290/angular-starter), I write this from logged in container
But I'm getting this error after installation
npm ERR! Maximum call stack size exceeded
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-09-17T17_38_34_855Z-debug.log
root#08e3cd77fb83:/work/angular-starter-master#
I was try to delete node_modules, but this problem is always.
Sometimes, after this error, when I again try npm install, console show me this:
npm ERR! path /work/angular-starter-
master/node_modules/#schematics/update/packa
ge.json.2932816706
npm ERR! code ETXTBSY
npm ERR! errno -26
npm ERR! syscall rename
npm ERR! ETXTBSY: text file is busy, rename '/work/angular-starter-
master/node_m
odules/#schematics/update/package.json.2932816706' -> '/work/angular-
starter-mas
ter/node_modules/#schematics/update/package.json'
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-09-17T17_14_43_970Z-debug.log
root#08e3cd77fb83:/work/angular-starter-master#
My npm version is 6.4.1
I have a Windows 8.1 and Docker Toolbox
But when I write npm install on Windows without Docker all is OK.
It might be because of different node versions. Check your node version with node -v and use that for the Dockerfile. Check the supported tags and Dockerfile links here: https://hub.docker.com/_/node
In the Dockerfile, I changed from FROM node:alpine AS node_builder to FROM node:lts-alpine AS node_builder and now it works.
Ok, i solved this problem, I was use npm install with --no-bin-links flag. Thanks for answers :)
For me, this ended up being caused by permission issues (I had previously install node_modules outside of docker). Deleting node_modules and only installing from within docker corrected the problem.

Docker Container works locally but fails on server

I'm fairly new to docker and I'm kind of experimenting with Angular CLI app. I managed to run it locally through my docker container. It works great, but when I try running it from my server it fails.
Server is hosted on DigitalOcean:
512 MB Memory / 20 GB Disk / FRA1 - Ubuntu Docker 17.03.0-ce on 14.04
I used dockerhub to transfer my container to the server.
When logging the container it gives me this:
** NG Live Development Server is running on http://0.0.0.0:4200. **
63% building modules 469/527 modules 58 active ...s/#angular/compiler/src/assertions.jsKilled
npm info lifecycle angular-test#0.0.0~start: Failed to exec start script
npm ERR! Linux 4.4.0-64-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v6.10.3
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! angular-test#0.0.0 start: `ng serve --host 0.0.0.0`
npm ERR! Exit status 137
npm ERR!
npm ERR! Failed at the angular-test#0.0.0 start script 'ng serve --host 0.0.0.0'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the angular-test package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! ng serve --host 0.0.0.0
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs angular-test
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls angular-test
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /usr/src/app/npm-debug.log
Here is my Dockerfile:
# Create image based on the official Node 6 image from dockerhub
FROM node:6
# Create a directory where our app will be placed
RUN mkdir -p /usr/src/app
# Change directory so that our commands run inside this new directory
WORKDIR /usr/src/app
# Copy dependency definitions
COPY package.json /usr/src/app
# Install dependecies
RUN npm install
# Get all the code needed to run the app
COPY . /usr/src/app
# Expose the port the app runs in
EXPOSE 4200
# Serve the app
CMD ["npm", "start"]
How come it runs locally and fails on server? Am I missing some dependencies?
ng serve is an angular-cli command. I'm guessing you need to install it globally in your docker file if you want to start your server like that on digital ocean:
RUN npm i -g angular-cli
I think it would be more typical to simply run the app using the naked node server in production. So your CMD would look more like this:
CMD ["node", "app.js"]

Resources