La aplicación nodejs no se conecta a localhost cuando se ejecuta dentro de un contenedor acoplable
My environment:
Ubunut 17.04 LTS
npm --version: 5.6.0
nodejs --version: 4.7.2
angular cli version: 1.6.4
docker-compose file:
version: '3'
services:
my-app:
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped
volumes:
- .:/usr/src/app
ports:
- "4200:4200"
Comenté el EXPOSE 4200 en dockerfile porque ya lo estoy montando desde el archivo docker-compose.yml, ¿no está bien? ¿Debería exponer en dockerfile y montar en docker-compose?
Ejecutar npm start en la línea de comandos inicia la aplicación con éxito en el navegador, ya que puedo accederlocalhost:4200
y ver la aplicación en ejecución.
Sin embargo, si construyo mi aplicación con docker y ejecuto docker-compose, veo que el servidor nodejs todavía se está ejecutando enlocalhost:4200
, sin embargo, NO PUEDO acceder a la aplicación, yendo alocalhost:4200
No aparece la página.
EJECUTAR LA APLICACIÓN FUNCIONA MANUALMENTE BIEN, PUEDO VERLO EN EL NAVEGADOR:
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.
EJECUTANDO LA APLICACIÓN DESDE DOCKER-COMPOSE FUNCIONA BIEN PERO NO PUEDO VER LA APLICACIÓN EN NAVEGADOR con localhost: 4200
Y desde docker-componer hasta
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.