【发布时间】:2018-06-25 10:24:39
【问题描述】:
My environment:
Ubunut 17.04 LTS
npm --version: 5.6.0
nodejs --version: 4.7.2
angular cli version: 1.6.4
docker-compose 文件:
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 服务器仍在 localhost:4200 上运行,但是,我无法访问该应用程序,转到 localhost: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 运行应用程序运行良好,但我在 localhost:4200 的浏览器上看不到应用程序
从 docker-compose up
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.
【问题讨论】:
-
分享你的 docker-compose.yml
标签: docker docker-compose dockerfile docker-swarm docker-machine