没有这样的文件或目录:Docker-compose up

问题描述 投票:1回答:1

我使用docker-compose将我的平均应用程序停靠。这很好用。现在我尝试使用“卷”,以便我的角度应用程序(使用ng服务)和我的快速应用程序(带有nodemon.js)在编码时自动重启。但角度和快速容器都出现相同的错误:

angular_1   |
angular_1   | up to date in 1.587s
angular_1   | found 0 vulnerabilities
angular_1   |
angular_1   | npm ERR! path /usr/src/app/package.json
angular_1   | npm ERR! code ENOENT
angular_1   | npm ERR! errno -2
angular_1   | npm ERR! syscall open
angular_1   | npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/app/package.json'
angular_1   | npm ERR! enoent This is related to npm not being able to find a file.
angular_1   | npm ERR! enoent
angular_1   |
angular_1   | npm ERR! A complete log of this run can be found in:
angular_1   | npm ERR!     /root/.npm/_logs/2019-04-07T20_51_38_933Z-debug.log
harmonie_angular_1 exited with code 254

查看文件夹层次结构:

-project
  -client
    -Dockerfile
    -package.json
  -server
    -Dockerfile
    -package.json
  -docker-compose.yml

这是我的角度Dockerfile:

# Create image based on the official Node 10 image from dockerhub
FROM node:10

# 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"]

我的Dockerfile for express:

# Create image based on the official Node 6 image from the 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 3000

# Serve the app
CMD ["npm", "start"]

最后我的docker-compose.yml

version: '3' # specify docker-compose version

# Define the services/containers to be run
services:
  angular: # name of the first service
    build: client # specify the directory of the Dockerfile
    ports:
      - "4200:4200" # specify port forwarding
#WHEN ADDING VOLUMES, ERROR APPEARS!!!!!!
    volumes:
      - ./client:/usr/src/app

  express: #name of the second service
    build: server # specify the directory of the Dockerfile
    ports:
      - "3000:3000" #specify ports forwarding
    links:
      - database
#WHEN ADDING VOLUMES, ERROR APPEARS!!!!!!
    volumes:
      - ./server:/usr/src/app

  database: # name of the third service
    image: mongo # specify image to build container from
    ports:
      - "27017:27017" # specify port forwarding
docker docker-compose dockerfile
1个回答
0
投票

你的卷部分应该是这样的:

    volumes:
      - .:/usr/app
      - /usr/app/node_modules

在Docker容器中安装源文件夹node_modules后,'覆盖',所以你需要添加'/ usr / app / node_modules'。完整的教程与适当的docker-compose.yml - https://all4developer.blogspot.com/2019/01/docker-and-nodemodules.html

© www.soinside.com 2019 - 2024. All rights reserved.