2

I'm trying to run with Docker compose an angular app. This is my Dockerfile of Angular container

# Stage 0, for downloading project’s npm dependencies, building and compiling the app.
FROM node:14.13 as node

# set working directory
RUN mkdir /usr/src/app
WORKDIR /usr/src/app

# add .bin to $PATH
ENV PATH /usr/src/app/node_modules/.bin:$PATH

# install package.json (o sea las dependencies)
COPY package.json /usr/src/app/package.json
RUN npm install
RUN npm install -g @angular/[email protected] 

# add app
COPY . /usr/src/app

# start app
CMD npm build-prod

# Stage 1, for copying the compiled app from the previous step and making it ready for production with Nginx
FROM nginx:alpine
COPY --from=node /usr/src/app/dist/bloomingfrontend /usr/share/nginx/html/
COPY nginx.conf /etc/nginx/conf.d/default.conf

docker-compose file:

version: '3.3'

services:
  web: 
    build: './blooming_frontend'
    ports: 
      - 80:80
    depends_on:
      - spring
  spring:
    build: ./blooming_backend
    ports:
      - 8080:8080

And nginx.conf

server {

    server_name localhost;
    listen      80;
    root        /usr/share/nginx/html;
    index       index.html index.htm;

    location / {

        try_files $uri $uri/ /index.html;

    }

}

As I seem in some tutorials it's fine to work, but when accessing localhost throws The localhost page has rejected the connection.

I'm new with Nginx and I dont know what I have to do

2 Answers 2

2

in your nginx configuration the localhost matches the container not the host (nginx will only accepts connections from the container itself). Removing the server_name line should make it works.

Sign up to request clarification or add additional context in comments.

Comments

0

For the case that somebody gets here.

For me, besides of changing the node version to 16.10 in the first line, this line did the trick:

RUN npm run build (instead of CMD npm build-prod)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.