gpt4 book ai didi

docker - 无法使用docker-compose运行vue-无法找到package.json

转载 作者:行者123 更新时间:2023-12-02 20:43:19 25 4
gpt4 key购买 nike

我无法使用Docker和docker-compose运行我的Vue应用程序。所有其他所有应用程序和服务都正在运行(一些.NET应用程序,nginx-proxy和letsencrypt-nginx-proxy-companion),但是在运行vue应用程序时,出现以下错误:

| npm ERR! path /app/package.json
| npm ERR! code ENOENT
| npm ERR! errno -2
| npm ERR! syscall open
| npm ERR! enoent ENOENT: no such file or directory, open '/app/package.json'
| npm ERR! enoent This is related to npm not being able to find a file.

这是我的docker-compose.yaml的样子:
version: "3.7"

services:
nginx-proxy:
image: jwilder/nginx-proxy:latest
container_name: nginx-proxy
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- /var/lib/docker/volumes/certs/_data:/etc/nginx/certs:ro
- /var/lib/docker/volumes/vhost/_data:/etc/nginx/vhost.d
- /var/lib/docker/volumes/html/_data:/usr/share/nginx/html
- /var/lib/docker/volumes/config/_data:/etc/nginx/conf.d
- /var/lib/docker/volumes/nginx/_data:/etc/init.d/
depends_on:
- app1
- app2
- vue-app
nginx-proxy-letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: nginx-proxy-letsencrypt
environment:
- DEFAULT_EMAIL=mail@mail.com
- NGINX_PROXY_CONTAINER=nginx-proxy
depends_on:
- nginx-proxy
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- /var/lib/docker/volumes/certs/_data:/etc/nginx/certs:rw
- /var/lib/docker/volumes/vhost/_data:/etc/nginx/vhost.d
- /var/lib/docker/volumes/html/_data:/usr/share/nginx/html
app1:
image: user/app1:latest
environment:
- VIRTUAL_HOST=example.com,www.example.com
- LETSENCRYPT_HOST=example.com,www.example.com
volumes:
- /var/lib/docker/volumes/sqllite/_data:/app/data
- /var/lib/docker/volumes/uploadfolder/_data:/app/wwwroot/uploads
app2:
build: ~/app_2
environment:
- VIRTUAL_HOST=app2.example.com,www.app2.example.com
- LETSENCRYPT_HOST=app2.example.com,www.app2.example.com
vue-app:
build: ~/vue_app
environment:
- VIRTUAL_HOST=vueapp.example.com,www.vueapp.example.com
- LETSENCRYPT_HOST=vueapp.example.com,www.vueapp.example.com
volumes:
- .:/app
- /app/node_modules
volumes:
certs:
vhost:
html:
networks:
default:
external:
name: nginx-proxy

还有我的vue-app的Docker文件:
# base image
FROM node:12.2.0-alpine

# set working directory
WORKDIR /app

# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH

# install and cache app dependencies
COPY package.json /app/package.json
RUN npm install
RUN npm install @vue/cli@3.7.0 -g

# start app
CMD ["npm", "run", "serve"]

我的服务器上的文件结构为:
root   
| docker-compose.yaml
|
|__app_2
| Dockerfile (in the project root)
|
|__vue_app
Dockerfile (in the project root)

我想念什么吗?

最佳答案

问题出在您的docker-compose.yaml文件中,您具有以下这一行:

vue-app:
...
volumes:
- .:/app

在这里,您只是使用当前目录的内容覆盖容器(包含 /app文件的容器)中 package.json目录的所有内容。
这就是为什么有错误告诉您文件不存在的原因。

关于docker - 无法使用docker-compose运行vue-无法找到package.json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59645645/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com