My environment:
Ubunut 17.04 LTS
npm --version: 5.6.0
nodejs --version: 4.7.2
angular cli version: 1.6.4
docker撰写文件:
version: '3'
services:
my-app:
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped
volumes:
- .:/usr/src/app
ports:
- "4200:4200"
我在dockerfile中注释掉了EXPOSE 4200,因为我已经从docker compose装载了它。yml文件,这样不行吗,我应该在dockerfile中公开并在docker compose中装载吗?
在命令行上运行npm start可在浏览器上成功启动应用程序,因为我可以转到
localhost:4200
并查看应用程序正在运行。
然而,如果我用docker构建应用程序并运行docker compose up,我会看到nodejs服务器仍在运行
本地主机:4200
,但是,我无法访问该应用程序,将转到
本地主机:4200
不会打开页面。
手动运行应用程序效果很好,我可以在浏览器上看到它:
ubuntu17@ubuntu17:~/playground/apps/myapp-ui$ ng serve
** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
Date: 2018-01-16T16:22:51.912Z
Hash: 40ac2bd0588ee2136d15
Time: 13963ms
chunk {inline} inline.bundle.js (inline) 5.79 kB [entry] [rendered]
chunk {main} main.bundle.js (main) 275 kB [initial] [rendered]
chunk {polyfills} polyfills.bundle.js (polyfills) 559 kB [initial] [rendered]
chunk {styles} styles.bundle.js (styles) 514 kB [initial] [rendered]
chunk {vendor} vendor.bundle.js (vendor) 12.1 MB [initial] [rendered]
webpack: Compiled successfully.
从DOCKER-COMPOSE UP运行应用程序运行正常,但我无法在localhost为4200的浏览器上看到该应用程序
由docker撰写
ubuntu17@ubuntu17:~/playground/apps/my-app-ui$ docker-compose up
Creating network "my-app_default" with the default driver
Creating my-app_my-app_1 ... done
Attaching to my-app_my-app_1
my-app_1 | ** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
my-app_1 | Date: 2018-01-16T16:28:05.444Z
my-app_1 | Hash: 40ac2bd0588ee2136d15
my-app_1 | Time: 13584ms
my-app_1 | chunk {inline} inline.bundle.js (inline) 5.79 kB [entry] [rendered]
my-app_1 | chunk {main} main.bundle.js (main) 271 kB [initial] [rendered]
my-app_1 | chunk {polyfills} polyfills.bundle.js (polyfills) 549 kB [initial] [rendered]
my-app_1 | chunk {styles} styles.bundle.js (styles) 511 kB [initial] [rendered]
my-app_1 | chunk {vendor} vendor.bundle.js (vendor) 12.1 MB [initial] [rendered]
my-app_1 |
my-app_1 | webpack: Compiled successfully.