我在使用Docker为Windows 10上的Angular 5提供开发环境时遇到了问题。
这是我的ng版本信息:
Angular CLI: 1.6.8
Node: 6.11.0
OS: win32 x64
Angular: 5.2.4
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cli: 1.6.8
@angular-devkit/build-optimizer: 0.0.42
@angular-devkit/core: 0.0.29
@angular-devkit/schematics: 0.0.52
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.8
@schematics/angular: 0.1.17
typescript: 2.5.3
webpack: 3.10.0
为了尝试找到我的问题的解决方案,我使用Angular CLI(最新版本)创建了一个新项目,docker-test使用:
ng new docker-test
然后我进入了docker-test并添加了一个dockerfile,如下所示:
FROM node:8
RUN mkdir -p /app
WORKDIR /app
COPY package.json /app/
RUN ["npm", "install"]
COPY . /app
EXPOSE 4200/tcp
EXPOSE 49153/tcp
CMD ["npm", "start"]
如果我从Powershell运行'ng serve',那么该应用程序可以毫无问题地提供服务。
然而,当尝试使用Docker时,我遇到了一个问题。
使用以下方法删除了所有图像和容器:
docker rmi $(docker images -q)
docker rm $(docker ps -a -q)
我可以使用以下方法成功构建图像:
docker build -t docker-test -f dockerfile .
并且可以使用以下命令'docker run'成功:
docker run --rm -it -p 4200:4200 -p 49153:49153 docker-test:latest
但是,如果我尝试使用卷来允许使用以下命令进行实时更新:
docker run -it --rm -p 4200:4200 -p 49153:49153 -v ${pwd}/src:/app/src docker-test
我收到以下错误:
ENOENT: no such file or directory, stat '/app/src/tsconfig.app.json'
Error: ENOENT: no such file or directory, stat '/app/src/tsconfig.app.json'
at Object.fs.statSync (fs.js:948:11)
at AngularCompilerPlugin._setupOptions (/app/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:78:16)
at new AngularCompilerPlugin (/app/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:43:14)
at _createAotPlugin (/app/node_modules/@angular/cli/models/webpack-configs/typescript.js:77:16)
at Object.getNonAotConfig (/app/node_modules/@angular/cli/models/webpack-configs/typescript.js:100:19)
at NgCliWebpackConfig.buildConfig (/app/node_modules/@angular/cli/models/webpack-config.js:41:37)
at Class.run (/app/node_modules/@angular/cli/tasks/serve.js:71:98)
at check_port_1.checkPort.then.port (/app/node_modules/@angular/cli/commands/serve.js:123:26)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! docker-test@0.0.0 start: `ng serve --host 0.0.0.0 --poll 500`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the docker-test@0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-02-12T19_50_23_145Z-debug.log
我无法解决问题所在。 该文件位于主机上:
如果我使用以下docker-compose.yaml文件,我会收到同样的错误:
version: '3'
services:
web: # name of the service
build: ./ # specify the directory of the Dockerfile
ports:
- "4200:80"
- "49153:49153"
volumes:
- '${pwd}/src:/app/src'
非常感谢收到有关该问题或如何调试的任何指导。