1
votes

Trying to run nginx and web application via docker compose

dockerfile

FROM node:12.16.2 as build

RUN mkdir /app

COPY package*.json ./
RUN npm install

COPY . /app
RUN npm run-script build

COPY --from=build /app/build /var/www/roundmap.app

EXPOSE 3000

nginx config defauls.conf

server {
  listen 80;
  listen 443 ssl;
  listen 3000;
  server_name *.roundmap.app 185.146.157.206;

  root /var/www/roundmap.app;
  index index.html;

  ssl_certificate /etc/ssl/roundmap/roundmap.crt;
  ssl_certificate_key /etc/ssl/roundmap/roundmap.key;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers HIGH:!aNULL:!MD5;

  if ($scheme = http) {
    return 301 https://$server_name$request_uri;
  }

  location / {
    proxy_pass https://app:3000;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
  }
}

docker-compose.yml

version: "4"
services:
    app:
        build: roundmap/
        container_name: app
        ports:
            - 3000:3000
    nginx:
        image: nginx:1.17.2-alpine
        container_name: nginx
        ports:
            - 80:80
            - 443:443
        links:
            - app
        volumes:
            - ./default.conf:/etc/nginx/conf.d/default.conf
            - /etc/ssl/roundmap/roundmap.crt:/etc/ssl/roundmap/roundmap.crt
            - /etc/ssl/roundmap/roundmap.key:/etc/ssl/roundmap/roundmap.key

running via docker-compose up and getting error

nginx | 2020/07/20 16:39:19 [emerg] 1#1: host not found in upstream "app" in /etc/nginx/conf.d/default.conf:22 nginx | nginx: [emerg] host not found in upstream "app" in /etc/nginx/conf.d/default.conf:22 nginx exited with code 1

Сan you please help where am I mistaken?

1
This might help.Muhammad Waqas Dilawar
Thank you, but I am goind add another container for rest api, it will use also 443 port and it is impossible to run miltiple containers on the same port, so need proxyOlga Polikashina

1 Answers

0
votes

In your default.conf replace https://app:3000 by http://app:3000 as SSL termination is happening at Nginx itself, app is still using http.

Update your docker-compose.yaml

Use depends_on instead of links, it has deprecated.

version: "3.8"
services:
    app:
        build: roundmap/
        container_name: app
        command: [ "node", "app.js"]
        ports:
            - 3000:3000
    nginx:
        image: nginx:1.17.2-alpine
        container_name: nginx
        ports:
            - 80:80
            - 443:443
        depends_on:
            - app
        volumes:
            - ./default.conf:/etc/nginx/conf.d/default.conf
            - /etc/ssl/roundmap/roundmap.crt:/etc/ssl/roundmap/roundmap.crt
            - /etc/ssl/roundmap/roundmap.key:/etc/ssl/roundmap/roundmap.key