I need to up a vue js app with docker-compose, but when docker trying 'npm install', the logs shows that npm cannot find a file package.json. Notice that i created a vue js project with vue js cli before i trying to up app with docker-compose* I verified if the directory is wrong, but i cannot see anything wrong . I'm running docker commands on vue project root. The docker-compose file is inside another project
My Dockefile:
FROM node:lts-alpine
RUN mkdir /globostore-frontend
WORKDIR /globostore-frontend
ENV PATH /globostore-frontend/node_modules/.bin:$PATH
COPY package.json /globostore-frontend
RUN npm install
RUN npm install -g #vue/cli
CMD ["npm", "run", "serve"]
My docker-compose.yml:
version: "3.8"
services:
db:
image: mysql:5.7
ports:
- '3306:3306'
environment:
MYSQL_DATABASE: 'Globostore'
MYSQL_USER: 'wendel'
MYSQL_PASSWORD: 'wendel12'
MYSQL_ROOT_PASSWORD: 'wendel12'
volumes:
- ./db:/docker-entrypoint-initdb.d/:ro
web:
build: .
command: flask run
volumes:
- .:/app
ports:
- '5000:5000'
depends_on:
- db
links:
- db
environment:
FLASK_ENV: development
bff:
build: ./../globostore-bff/
ports:
- 5001:5001
volumes:
- .:/app
environment:
FLASK_ENV: development
command: flask run
frontend:
build: ./../globostore-frontend/
volumes:
- .:/globostore-frontend
ports:
- 8080:8080
Error:
frontend_1 | npm ERR! code ENOENT
frontend_1 | npm ERR! syscall open
frontend_1 | npm ERR! path /globostore-frontend/package.json
frontend_1 | npm ERR! errno -2
frontend_1 | npm ERR! enoent ENOENT: no such file or directory, open '/globostore-frontend/package.json'
frontend_1 | npm ERR! enoent This is related to npm not being able to find a file.
frontend_1 | npm ERR! enoent
frontend_1 |
frontend_1 | npm ERR! A complete log of this run can be found in:
frontend_1 | npm ERR! /root/.npm/_logs/2021-02-02T17_00_23_137Z-debug.log
This is my project directory structure
I start the application through the docker-compose file at globostore-api directory
Issue
It looks like your error does not come from docker build. It looks like it comes from from this command: npm run serve executed during container start.
During docker build your npm install will work, because the package.json exists - You copy it.
But when you run docker-compose up this file does not exists because you override entire directory with volumes for frontend.
You have docker-compose.yaml next to those files:
.gitignore
app.py
Dockerfile
Readme.md
requirements.txt
There is no package.json file, in that directory, you mount inside the docker-compose.yaml
In docker-compose you have this section:
frontend:
build: ./../globostore-frontend/
volumes:
- .:/globostore-frontend
ports:
- 8080:8080
So you are overwriting volume here: - .:/globostore-frontend, you copied in docker build.
Solution
Remove this line
Replace .:/globostore-frontend to ./globostore-frontend:/globostore-frontend
Do debugging yourself
You can do debugging yourself. Please find tutorial and follow my instructions:
1. Add command to docker-compose.yaml for the frontend service
You need to add this line: command: ["sleep", "10000"]
So your definition will look like:
frontend:
build: ./../globostore-frontend/
volumes:
- .:/globostore-frontend
ports:
- 8080:8080
command: ["sleep", "1000"]
Then try to run docker-compose up and see if your container is working.
2. Find docker container ID
Run docker ps and find container id - this is container hash.
3. Shell into container
Run docker exec -ti CONTAINER_ID sh. Now you are in the container and you can see if the package.json exists in the /globostore-frontend directory.
But the package.json will be missing because you override the /globostore-frontend dir with volume for a frontend in this lines:
volumes:
- .:/globostore-frontend
Related
I am writing here a new question, because i can't find solution of my problem.
I am trying to build this for two days.
TLDR:
I am building a vue project with vite. Everything is fine, when i use npm run dev
Also, everything looks fine when i build docker-compose inside frontend directory.
I need to place docker-compose outside of this dir, cuz i would like to create more dockers like backend, nginx, postress.
Dockerfile:
# build stage
FROM node:lts-alpine as build-stage
WORKDIR /app
RUN npm install -g npm
COPY package*.json ./
RUN npm install
docker-compose.yml:
version: "3.9"
services:
frontend:
build:
context: frontend/
dockerfile: Dockerfile
working_dir: /app
command: ["npm", "run", "dev"]
env_file:
- config/env/server-developer.env
environment:
- CHOKIDAR_USEPOLLING=true
volumes:
- type: volume
source: node_modules
target: /app/node_modules
ports:
- 8080:8080
volumes:
node_modules:
project build:
this is project location
okey, so, when i use docker-compose -f docker-compose.yml up --build
i got this output:
Recreating project_frontend_1 ... done
Attaching to project_frontend_1
frontend_1 |
frontend_1 | > frontend#0.0.0 dev
frontend_1 | > vite --host 0.0.0.0
frontend_1 |
frontend_1 | sh: vite: not found
project_frontend_1 exited with code 127
If you need more information, i will add. I know that most ppl use dockers, but i can't find solution that can help me with it. Someone said that vite is not installed globaly, i can't finde npm install comand to install as dependency in package.json.
Experiencing first setups with Docker with several services running.
Spent a while on this, but cannot pinpoint the problem.
Below is the cause of the problem, I think.
Why the Node app does not work/start?
web_1 | npm ERR! code ENOENT
web_1 | npm ERR! syscall open
web_1 | npm ERR! path /app/http/app/package.json
web_1 | npm ERR! errno -2
web_1 | npm ERR! enoent ENOENT: no such file or directory, open '/app/http/app/package.json'
web_1 | npm ERR! enoent This is related to npm not being able to find a file.
web_1 | npm ERR! enoent
web_1 |
web_1 | npm ERR! A complete log of this run can be found in:
web_1 | npm ERR! /root/.npm/_logs/2020-12-27T23_32_03_845Z-debug.log
Why it does not see it:
docker-compose.yml
version: '3'
services:
mongo:
image: mongo
restart: always
ports:
- "27017:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: mongo_user
MONGO_INITDB_ROOT_PASSWORD: mongo_secret
api:
build:
context: .
dockerfile: Dockerfile
restart: always
ports:
- "4433:4433"
depends_on:
- rabbit
volumes:
- .:/app
web:
build:
context: .
dockerfile: Dockerfile1
restart: always
ports:
- "8080:8080"
depends_on:
- api
volumes:
- .:/app
rabbit:
hostname: rabbit
image: rabbitmq:management
environment:
- RABBITMQ_DEFAULT_USER=rabbitmq
- RABBITMQ_DEFAULT_PASS=rabbitmq
ports:
- "5673:5672"
- "15672:15672"
worker_1:
build:
context: .
hostname: worker_1
entrypoint: celery
command: -A workerA worker --loglevel=info -Q workerA
volumes:
- .:/app
links:
- rabbit
depends_on:
- rabbit
Dockerfile
FROM python:3.8
ADD Pipfile.lock /app/Pipfile.lock
ADD Pipfile /app/Pipfile
WORKDIR /app
COPY . /app
RUN pip install pipenv
RUN pipenv install --system --deploy --ignore-pipfile
ENV FLASK_APP=app/http/api/endpoints.py
ENV FLASK_RUN_PORT=4433
ENV FLASK_ENV=development
ENTRYPOINT ["python"]
#CMD ["app/http/api/endpoints.py","--host=0.0.0.0","--port 4433"]
CMD ["-m", "flask", "run"]
Dockerfile1
FROM node:10
WORKDIR /app/http/app
ADD app/http/app/package.json /app/http/app/package.json
ADD app/http/app/package-lock.json /app/http/app/package-lock.json
RUN npm i
CMD ["npm","start"]
How to make such a setup
Flask, RabbitMQ, React????
How to make it properly?
I am running Docker on Windows 10 and when I run docker-compose up -d I get this errror but I don't know why.
npm WARN saveError ENOENT: no such file or directory, open '/var/www/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/var/www/package.json'
npm WARN www No description
npm WARN www No repository field.
npm WARN www No README data
npm WARN www No license field.
Here is my docker-compose.yaml file
version: '3'
services:
# Nginx client app server
nginx-client:
container_name: nginx-client
build:
context: ./docker/nginx-client
dockerfile: Dockerfile
restart: unless-stopped
ports:
- 28874:3000
volumes:
- ./client:/var/www
networks:
- app-network
# Networks
networks:
app-network:
driver: bridge
And here is my Dockerfile
FROM node:12
WORKDIR /var/www
RUN npm install
CMD ["npm", "run", "serve"]
This is happening because first you are building an image out of your Dockerfile, which contains this commands:
WORKDIR /var/www
RUN npm install
But right now this directory is empty. It's only after the container is created, bind mounting will take place. You can read more about it in the docs, it states:
A service definition contains configuration that is applied to each
container started for that service, much like passing command-line
parameters to docker run. Likewise, network and volume definitions are
analogous to docker network create and docker volume create.
If you need to have this file available at the image build time, I'd suggest using COPY command, like:
COPY ./client/package*.json ./
RUN npm install
This is the docker-compose file I have already set the folder to share by Virtual Box VM but it is still not working.
version: '3'
services:
postgres:
image: 'postgres:latest'
deploy:
restart_policy:
condition: on-failure
window: 15m
redis:
image: 'redis:latest'
nginx:
restart: always
build:
dockerfile: Dockerfile.dev
context: ./nginx
ports:
- '3050:80'
api:
build:
dockerfile: Dockerfile.dev
context: ./server
volumes:
- /usr/src/app/node_modules
- ./server:/usr/src/app
environment:
- REDIS_HOST=redis
- REDIS_PORT=6379
- PGUSER=postgres
- PGHOST=postgres
- PGDATABASE=postgres
- PGPASSWORD=postgres_password
- PGPORT=5432
client:
build:
dockerfile: Dockerfile.dev
context: ./client
volumes:
- /usr/src/app/node_modules
- ./client:/usr/src/app
worker:
build:
dockerfile: Dockerfile.dev
context: ./worker
volumes:
- /usr/src/app/node_modules
- ./worker:/usr/src/app
I am running it on Windows 7 sp1. Whenever I run docker-compose up - I get an error:
api_1 | npm ERR! code ENOENT
api_1 | npm ERR! syscall open
api_1 | npm ERR! path /usr/src/app/package.json
api_1 | npm ERR! errno -2
api_1 | npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/
app/package.json'
api_1 | npm ERR! enoent This is related to npm not being able to find a fi
le.
api_1 | npm ERR! enoent
api_1 |
api_1 | npm ERR! A complete log of this run can be found in:
api_1 | npm ERR! /root/.npm/_logs/2020-05-28T04_06_56_121Z-debug.log
complex_api_1 exited with code 254
Thanks in advance, please help.
I am trying to run a Fibonacci project from the Udemy course of Docker and Kubernetes complete guide.
Each service has its own package.json and other files.
Server Docker File :
FROM node:alpine
WORKDIR /usr/src/app
COPY package.json .
RUN npm install
COPY . .
CMD ["npm", "run", "dev"]
Worker Docker File :
FROM node:alpine
WORKDIR /usr/src/app
COPY package.json .
RUN npm install
COPY . .
CMD ["npm", "run", "dev"]
Client Docker File :
FROM node:alpine
WORKDIR /usr/src/app
COPY package.json .
RUN npm install
COPY . .
CMD ["npm", "run", "start"]
If you want to share data between containers
services:
client:
build:
dockerfile: Dockerfile.dev
context: ./client
volumes:
- datavolume:/usr/src/app/node_modules
- ./client:/usr/src/app
worker:
build:
dockerfile: Dockerfile.dev
context: ./worker
volumes:
- datavolume:/usr/src/app/node_modules
- ./worker:/usr/src/app
volumes:
datavolume: {}
Since it looks like your dev, I would suggest mount your workspace folder into container
services:
client:
build:
dockerfile: Dockerfile.dev
context: ./client
volumes:
- ./node_modules:/usr/src/app/node_modules
- ./client:/usr/src/app
worker:
build:
dockerfile: Dockerfile.dev
context: ./worker
volumes:
- ./node_modules:/usr/src/app/node_modules
- ./worker:/usr/src/app
And better way is treating every service a standalone project. Each of them should own their self package.json and node_modules.
services:
client:
build:
dockerfile: Dockerfile.dev
context: ./client
volumes:
- ./client:/usr/src/app
worker:
build:
dockerfile: Dockerfile.dev
context: ./worker
volumes:
- ./worker:/usr/src/app
In my opinion, it doesn't make sense to use same libraries in different project which in different purpose.
I had the same error! Actually I solved moving my project to /c/Users/currentUser from c/Program Files/Docker Toolbox. Maybe you have your project folder inside Program Files directory and not inside Users one, is It right? Try with this, Just Copy your project folder inside users and running your docker-compose from there. Let me know!
I'm setting up Gitlab CI docker-in-docker for a project. Unfortunately the job keeps failing because installed NPM packages can't seem to be found when running commands. The error I'm getting:
backend_1 |
backend_1 | > tacta-backend#0.0.1 build /app
backend_1 | > tsc
backend_1 |
backend_1 | sh: tsc: not found
backend_1 | npm ERR! file sh
backend_1 | npm ERR! code ELIFECYCLE
backend_1 | npm ERR! errno ENOENT
backend_1 | npm ERR! syscall spawn
backend_1 | npm ERR! tacta-backend#0.0.1 build: `tsc`
backend_1 | npm ERR! spawn ENOENT
backend_1 | npm ERR!
backend_1 | npm ERR! Failed at the tacta-backend#0.0.1 build script.
backend_1 | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
backend_1 |
backend_1 | npm ERR! A complete log of this run can be found in:
backend_1 | npm ERR! /root/.npm/_logs/2019-08-02T04_46_04_881Z-debug.log
The curious thing is that it does work when I run docker-compose manually without using the Gitlab CI. This is what my .gitlab-ci.yml looks like:
build:
variables:
DOCKER_HOST: tcp://docker:2375/
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
image: docker:18
stage: build
services:
- docker:18-dind
before_script:
- docker info
- apk add python-dev libffi-dev openssl-dev gcc libc-dev make
- apk add py-pip
- pip install docker-compose
script:
- docker-compose -f docker-compose.yml -f docker-compose.prod.yml up
This is my docker-compose.yml:
version: '3'
services:
frontend:
build:
context: ./frontend
args:
NODE_ENV: production
PGUSER: ${PGUSER}
PGHOST: ${PGHOST}
PGPASSWORD: ${PGPASSWORD}
PGDATABASE: ${PGDATABASE}
PGPORT: ${PGPORT}
DATABASE_URL: ${DATABASE_URL}
command: npm run build
ports:
- "9000:9000"
volumes:
- /app/node_modules
- ./frontend:/app
backend:
build:
context: ./backend
args:
NODE_ENV: production
command: npm run build
ports:
- "3000:3000"
volumes:
- /app/node_modules
- ./backend:/app
And this is the Dockerfile:
FROM node:11.10.1-alpine
ARG NODE_ENV
ARG PGUSER
ARG PGHOST
ARG PGPASSWORD
ARG PGDATABASE
ARG PGPORT
ARG DATABASE_URL
ENV NODE_ENV ${NODE_ENV}
ENV PGUSER ${PGUSER}
ENV PGHOST ${PGHOST}
ENV PGPASSWORD ${PGPASSWORD}
ENV PGDATABASE ${PGDATABASE}
ENV PGPORT ${PGPORT}
ENV DATABASE_URL ${DATABASE_URL}
WORKDIR '/app'
COPY ./package.json ./
RUN npm install
COPY ./ ./
I expect the installed packages and their commands to be available in the docker container. At some point they worked, and I have no clue what changed in the configuration to cause this issue.
I am not expecting a copy/paste solution from you guys, but I do hope you can point me in the right direction to properly get to the root of this issue.
The problem was that I switched from NODE_ENV: development to NODE_ENV: production. With production enabled devDependencies in my package.json were no longer being installed (duh me).
I added typescript and webpack to the regular dependencies and now it works like a charm again.