express API的Dockerfile就像这样:
FROM node:10.15.3
MAINTAINER AshishkrGoyal <ashish.goyal@algoscale.com>
#RUN mkdir -p /usr/src/app
#define working dir
WORKDIR /usr/src/app
#available package.json, package-lock.json as well
COPY package*.json ./
#install all dependencies listed in package.json
RUN npm install
#copy all the source code to working dir
COPY . .
#mapping of port to docker daemon
EXPOSE 3000
#command in the form of array
CMD ["npm", "run", "dev"]
docker-compose.yml如下所示:
#specify the docker-compose version
version: '3.0'
services:
#specify all the services
angular: #it is frontend service container name
build: public #dockerfile directory
ports:
- "4200:4200"
express: #it is backend service container name
build: server #dockerfile directory
ports:
- "3000:3000"
links:
- database
database: #it is elastc search service container name
image: docker.elastic.co/elasticsearch/elasticsearch:7.0.0
ports:
- "9200:9200"
在运行命令docker-compose时,出现以下错误: 错误:服务“ express”无法生成:COPY失败:未指定源文件
请帮助我解决此错误。
提前谢谢!
答案 0 :(得分:0)
#copy all the source code to working dir
COPY . .
这将复制 host 的当前目录,这是映像创建过程的一部分。 docker-compose up ...
是否从Express项目的根目录执行?否则,创建映像时将找不到Express项目文件。
答案 1 :(得分:0)
请检查您的.gitignore
文件是否忽略了源文件。