I am trying to deploy a ng angular application using the nginx. But it doesn’t seem to listen to the right port for whatever reason.
To better explain, I use this dockerfile to create a docker container after I ran ng build --configuration=production:
FROM nginx:latest
# Copy the built Angular app into the Nginx web server directory
COPY ./dist/angular_template /usr/share/nginx/html
# Expose the default Nginx port
EXPOSE 80
# Start Nginx when the container starts
CMD ["nginx", "-g", "daemon off;"]
Then I use the fly deploy --image "name/of/image"
and this is my fly.toml configuration:
# fly.toml app configuration file generated for frontend-bikes4all on 2023-11-23T16:09:14+02:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#
app = "frontend-bikes4all"
primary_region = "otp"
[build]
image = "ghcr.io/inginerie-software-2023-2024/proiect-inginerie-software-ando-foro/bikes4all-frontend:latest"
[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
processes = ["app"]
I get this log when I try to deploy using fly deploy --image
You can fix this by configuring your app to listen on the following addresses:
- 0.0.0.0:8080g that 17811e16f20d58 [app] is up and running
Found these processes inside the machine with open listening sockets:
PROCESS | ADDRESSES
---------------------------------------------*---------------------------------------
nginx: master process nginx -g daemon off; | 0.0.0.0:80, [::]:80
/.fly/hallpass | [fdaa:2:8f90:a7b:1ad:55db:f54d:2]:22
nginx: worker process | 0.0.0.0:80, [::]:80
I don’t really understand what seems to be the problem here, cause it seems that nginx master porcess is listening to 0.0.0.0:80 so why is this not connecting?
this shows in the logs of the fly monitoring:
instance refused connection. is your app listening on 0.0.0.0:8080? make sure it is not only listening on 127.0.0.1 (hint: look at your startup logs, servers often print the address they are listening on)
Got it now, also, it came to an end as I noticed that routing isn’t working pretty well with default ng, so now I am trying to use a node.js express server to serve the build. This is my server.js:
And i tested it, and node server.js works perfectly. Now my question is of course, how to modify the Dockerfile to get the build and serve the node.js?
I thought there should be more details to it, I need a dockerfile so I can push the image to a git registry, and then pull that image and use fly deploy --local-only because the git package is private, so it can’t be built remotely. thanks
Thank you for your help. I’ll reply in case of anyone relating to this issue or wanting to deploy an angular app, it turned out to be more simple than I thought. This is the Docker config I’m running to deploy the express server that serves the angular build:
ARG NODE_VERSION=20.4.0
FROM node:${NODE_VERSION}-slim as base
LABEL fly_launch_runtime="Node.js"
# Set the working directory
WORKDIR /app
# Copy the built Angular build - or run ng build
COPY ./dist/angular_template ./dist/angular_template
# Copy the server handler
COPY ./server.js ./
#COPY ./package.json ./
#COPY ./package-lock.json ./
#RUN npm install
RUN npm install express
# Expose the default Nginx port
EXPOSE 80
# Start Nginx when the container starts
CMD ["node", "server.js"]
Remember to add ng build , package.json and run npm install if it’s the case. I didn’t because I export this to a workflow where the machine already imports and installs those