I have a front app who uses Angular-cli and i’am trying to check if it works proprely separetly before integrating it in the container core but it seems that i can’t get acces to the localhost.
I’am using a macOS Catalina 10.15.7 with Docker Desktop.
My Dockerfile is build like this:
FROM node:14-alpine3.12
WORKDIR /app/front
#COPY ./angular-cli .
COPY package.json package-lock.json
COPY . .
RUN npm install
RUN npm install -g @angular/cli
EXPOSE 4200
# Angular installation if it fails,
CMD ["ng", "serve"]
And when i run the app with the command:
docker run -d -p 80:4200 reponame
it works fine with no error at all and shows me this:
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
Compiled successfully.
and when i go to Localhost:4200 it shows that the page is not accessible.
i also tried to connect with Ip adress using this commands but same thing.
docker inspect -f ‘{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}’
If anyone can help me, would really greatfull.
Thanks !
You just forwarded your local port 80 to the container port 4200. localhost:4200 won’t work outside the container.
Using the container IP won’t work either since the containers are runing inside a virtual machine. Try localhost:80 from your host or forward port 4200 to the container instead of port 80.
Well like i said in my previous comment here, i tried to port it to 80, and i did localhost:80 but it didn’t work, same thing.
I run my docker in the 80 port.
I can’t find that part of your comment. I saw you forwarded port 80 but not trying to access through that port. If you did try it then it was a misunderstanding, but that should have worked
@tazbiopooltech, in case it helps, on a Mac lsof -i :port will tell what is listening. Like below 5432 is used for a container running my PostgreSQL database:
~ lsof -i :5432
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
com.docke 15228 avanbentem 114u IPv6 0xfc6e512f1617cbb 0t0 TCP *:postgresql (LISTEN)
Also, I’d expect docker run -p to complain when using a port that is already in use:
docker run --rm -it -p 5432:443 busybox
docker: Error response from daemon: driver failed programming external connectivity on endpoint vigilant_banach (...): Bind for 0.0.0.0:5432 failed: port is already allocated.
Are you sure the app allows connections for non-localhost (so: is listening on 0.0.0.0 in the container?)
Well if you mean that when i try to run it in: -host 0.0.0.0
i got this output:
got this error when typing the run command in port 80. An unhandled exception occurred: getaddrinfo ENOTFOUND O.O.O.O See “/tmp/ng-aAAkli/angular-errors.log” for further details.
ng serve --host 0.0.0.0
Your global Angular CLI version (13.0.4) is greater than your local version (11.2.8). The local Angular CLI version is used.
To disable this warning use "ng config -g cli.warnings.versionMismatch false".
? Port 4200 is already in use.
Would you like to use a different port? Yes
Warning: This is a simple server for use in testing or debugging Angular applications
locally. It hasn't been reviewed for security issues.
Binding this server to an open connection can result in compromising your application or
computer. Using a different host than the one passed to the "--host" flag might result in
websocket connection issues. You might need to use "--disableHostCheck" if that's the
case.
✔ Browser application bundle generation complete.
Initial Chunk Files | Names | Size
styles.css | styles | 15.71 MB
vendor.js | vendor | 9.12 MB
scripts.js | scripts | 691.12 kB
main.js | main | 224.87 kB
polyfills.js | polyfills | 128.73 kB
runtime.js | runtime | 6.15 kB
| Initial Total | 25.85 MB
Build at: 2021-12-02T15:17:52.924Z - Hash: a1fe9448a2733e019729 - Time: 41442ms
** Angular Live Development Server is listening on 0.0.0.0:35145, open your browser on http://localhost:35145/ **
✔ Compiled successfully.
And same output again nothing happens
Site note reachable