无法弄清楚为什么docker compose up没有运行我的React JS App [英] Not able to figure out why docker compose up is not running my React JS App

查看:86
本文介绍了无法弄清楚为什么docker compose up没有运行我的React JS App的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想借助docker-compose和docker文件在docker容器中运行react应用。它显示缺少package.json文件,但是我确实在尝试与docker容器映射的本地目录中有该文件。

I want to run a react app in a docker container with the help of a docker-compose and docker file. It is showing package.json file is missing but I do have that file in my local directory which I am trying to map with the docker container.

我已经通过运行 docker-compose build 命令成功构建了映像。但是,当我尝试运行 docker-compose up 命令时,它显示在错误下方

I have successfully built the image by running docker-compose build command. But while I am trying to run docker-compose up command it is showing below error

PS E:\Project\MyProfile\my-profile> docker-compose up   
Starting myprofile_web_1 ... done
Attaching to myprofile_web_1
web_1  | npm ERR! code ENOENT
web_1  | npm ERR! syscall open
web_1  | npm ERR! path /app/package.json
web_1  | npm ERR! errno -2
web_1  | npm ERR! enoent ENOENT: no such file or directory, open '/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-06-03T16_54_28_610Z-debug.log
myprofile_web_1 exited with code 254 

我的机器是Windows 10,请告知我是否需要更多信息。

My machine is Windows 10 and let me know if you all need any further information.

我的Docker文件:

My Docker File:

FROM node:alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD [ "npm","run","start" ]

Docker Compose File :

Docker Compose File:

version: '3'
services: 
    web:
        build:
            context: .
            dockerfile: Dockerfile.dev
        ports: 
            - 3000:3000
        volumes: 
            - /app/node_modules
            - .:/app

更新1:

正如彼得建议的那样,我在Docker容器中查看 app目录,在那里可以看到package.json文件。

As Peter suggested I look into 'app' directory in the Docker container I can see package.json file there.

更新2

文件权限日志

PS E:\Project\MyProfile\my-profile> docker run website ls -lah
total 724K
drwxr-xr-x    1 root     root        4.0K Jun  6 16:03 .
drwxr-xr-x    1 root     root        4.0K Jun  6 16:07 ..
-rwxr-xr-x    1 root     root          17 Jun  5 16:55 .dockerignore
drwxr-xr-x    7 root     root        4.0K Apr 20 16:02 .git
-rwxr-xr-x    1 root     root         310 Oct 26  1985 .gitignore
drwxr-xr-x    2 root     root        4.0K Apr 18 10:53 .vscode
-rwxr-xr-x    1 root     root         190 Jun  4 18:08 Dockerfile.dev
-rwxr-xr-x    1 root     root       52.6K Sep 21  2019 MyProfile.png
-rwxr-xr-x    1 root     root        2.8K Oct 26  1985 README.md
drwxr-xr-x    3 root     root        4.0K Apr 16 17:34 build
drwxr-xr-x    3 root     root        4.0K Oct  2  2019 config
-rwxr-xr-x    1 root     root         274 Jun  4 17:54 docker-compose.yml
-rwxr-xr-x    1 root     root         610 Apr 24 05:11 eg.js
drwxr-xr-x 1056 root     root       36.0K Jun  6 15:59 node_modules
-rw-r--r--    1 root     root      562.9K Jun  6 15:59 package-lock.json
-rwxr-xr-x    1 root     root        3.8K Apr  5 08:34 package.json
drwxr-xr-x    2 root     root        4.0K Apr 20 05:03 public
drwxr-xr-x    2 root     root        4.0K Oct  2  2019 scripts
drwxr-xr-x    6 root     root        4.0K Apr 15 16:44 src

解决方案:

我能够通过将Project移到C:/ User / {User_Name}文件夹来解决此问题。可以在此处找到相同的解释(​​找不到Docker卷和package.json

I was able to resolve this issue by moving my Project to C:/User/{User_Name} folder. Explaination for the same can be found here (Docker volumes and package.json not found)

如果您不想像我一样移动文件夹,也可以将其签出(如何在docker计算机中安装本地卷

If you do not want to move folders just like me you can do that as well checkout this (How to mount local volumes in docker machine)

推荐答案

我能够通过将Project移到C:/ User / {User_Name}文件夹来解决此问题。相同的说明可以在这里找到(​​找不到Docker卷和package.json )。

I was able to resolve this issue by moving my Project to C:/User/{User_Name} folder. The explanation for the same can be found here (Docker volumes and package.json not found).

如果您不想像我一样移动文件夹,也可以将其签出(如何在docker计算机中安装本地卷

If you do not want to move folders just like me you can do that as well checkout this (How to mount local volumes in docker machine)

这篇关于无法弄清楚为什么docker compose up没有运行我的React JS App的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆