1

Dockerfile:

FROM node:current-alpine3.10

RUN mkdir -p /dist/angular

WORKDIR /dist/angular

COPY package.json .

RUN npm install --legacy-peer-deps

COPY . .

EXPOSE 8500

CMD ["npm","run","start:stage-ena-sso"]

package.json:

...
  "scripts": {
    "start:stage-ena-sso": "ng serve -o -c=stage-ena-sso --port=8500 --baseHref=/"
  }...

Folder structure:
enter image description here

Command used to build the Docker image:

docker build . -t ssoadminuiapp

Command used to run the Docker image:

docker run --rm -it  -p 8500:8500/tcp ssoadminuiapp:latest

Check if container is running:

CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS                    NAMES
8959e5180eba        ssoadminuiapp:latest   "docker-entrypoint.s…"   6 minutes ago       Up 6 minutes        0.0.0.0:8500->8500/tcp   recursing_fermat

But accessing localhost:8500 doesnt seem to work:
enter image description here

I'm really new to Docker, so any useful beginner-friendly tips/infos would be very appreciated.

Edit #1, this is the result after running docker run command:
enter image description here

R. Richards
  • 23,283
  • 10
  • 63
  • 62
Henry
  • 453
  • 5
  • 20

1 Answers1

2

This is the problem:

Angular Live Development Server is listening on localhost:8500

Because your application is bound to localhost inside the container, the port isn't available for port forwarding. That's like trying to run a service on your host bound to localhost -- you can reach it locally, but nothing remote can connect to it (and from a network perspective, you host is "remote" from the container).

You'll need to configure the Angular server to bind to all addresses in the container (0.0.0.0). I'm not sure exactly how to do this in your application; when running ng serve from the command line there is a --host option to set the bind address.

larsks
  • 228,688
  • 37
  • 348
  • 338
  • You mean something like this? "start:stage-ena-sso": "ng serve -o -c=stage-ena-sso --port=8500 --baseHref=/ --host=0.0.0.0" – Henry Mar 17 '21 at 11:26
  • Thank you @larsks, you answer solved the issue :) – Henry Mar 17 '21 at 11:58
  • 1
    Excellent! I'm not familiar with Angular or npm so while I can tell you the solution I'm sorry I wasn't able to provide more explicit guidance. Glad you figured it out! – larsks Mar 17 '21 at 11:59