How to get to another container from docked nginx

I have nginx in a docker container and nodejs webapp in another docker container. The nodejs server is accessible from the host server on port 8080.

The dginx nginx container listens on port 80 (it will later execute the certificate, this database should work first).

And now I want the subdomain to be forwarded to this 8080 nodejs application. let's say app1.example.com

From the outside, I can get to the application using the IP server (or host name) and port 8080, but not on app1.example.com. And it works on app1.example.com:8080 (I opened port 8080 on the host server).

I get a message about the wrong nginx gateway when approaching app1.example.com So, I got to the first nginx container, but how do I return to the host server so that the proxy sends it to port 8080 of the host server (and not port 8080 nginx container). looking for the inverse syntax of EXPOSE.

The main problem is, of course, if I use ip and port 127.0.0.1:8080, it will try to use the nginx container .... So, how do I get the nginx container route back to host 127.0.0.1:8080?

I tried 0.0.0.0 and determined upstream, actually a lot of googling, and tried a lot of configurations ... but haven't found a working one yet ...

Edit Just found out, this docker command can help:

sudo docker network inspect bridge

Ip, ( 172.17..0.2), , ... (, )

Edit Followning ( ):

docker-compose.yml:

version: "2"
services:
  nginx:
    container_name: nginx
    image: nginx_img
    build: ../docker-nginx-1/
    ports:
      - "80:80"
    networks:
      - backbone
  nodejs:
    container_name: nodejs
    image: merites/docker-simple-node-server
    build: ../docker-simple-node-server/
    networks:
    - backbone
    expose: 
    - 8080
  networks:
    backbone:
      driver: bridge

nginx ( conf.d):

worker_processes 1;

{worker_connections 1024; }

http {

  sendfile on;

  upstream upsrv {
      server nodejs:8080;
  }

  server {

    listen 80;
    server_name  app1.example.com;

    location / {
        proxy_pass http://upsrv;
    }

  }
}

31-08-2016

this migth , , , srevice :

sudo docker network ls

out puts:

NETWORK ID          NAME                       DRIVER              SCOPE
1167c2b0ec31        bridge                     bridge              local               
d06ffaf26fe2        dockerservices1_backbone   bridge              local               
5e4ec13d790a        host                       host                local               
7d1f8c32f259        none                       null                local 

edit 01-09-2016

, nginx docker?

, :

############################################################
# Dockerfile to build Nginx Installed Containers
# Based on Ubuntu
############################################################

# Set the base image to Ubuntu
FROM ubuntu

# File Author / Maintainer
MAINTAINER Maintaner Name

# Install Nginx

# Add application repository URL to the default sources
# RUN echo "deb http://archive.ubuntu.com/ubuntu/ raring main     universe"     >> /etc/apt/sources.list

# Update the repository
RUN apt-get update

# Install necessary tools
RUN apt-get install -y nano wget dialog net-tools

# Download and Install Nginx
RUN apt-get install -y nginx  

# Remove the default Nginx configuration file
RUN rm -v /etc/nginx/nginx.conf

# Copy a configuration file from the current directory
ADD nginx.conf /etc/nginx/

# Append "daemon off;" to the beginning of the configuration
RUN echo "daemon off;" >> /etc/nginx/nginx.conf

# Expose ports
EXPOSE 80

# Set the default command to execute
# when creating a new container
CMD service nginx start

1- . 2016

:

version: "2"
services:
    nginx:
      image: nginx
      container_name: nginx
      volumes:
        - ./nginx-configs:/etc/nginx/conf.d
      ports:
        - "80:80"
      networks:
        - backbone
    nodejs:
      container_name: nodejs
      image: merites/docker-simple-node-server
      build: ../docker-simple-node-server/
      networks:
        - backbone
      expose: 
        - 8080
networks:
  backbone:
    driver: bridge

, docker-compose up -d, nginx-configs. "" nginx /etc/nginx/conf.d

default.cfg nginx, . :

docker exec -t -i _/bin/bash

cat/etc/nginx/conf.d/default.conf

default.conf nginx.

app1.conf :

upstream upsrv1 {
    server nodejs:8080;
}

server {

    listen 80;
    server_name  app1.example.com;


    location / {
        proxy_pass http://upsrv1;
    }

}

, ... ..

, ...

+4
1

. 80 . nodejs , nginx.

version: "2"
services:
    nginx:
      ...
      ports:
        - "80:80"
      networks:
        - backbone
    nodejs:
      ...
      networks:
        - backbone
      expose: 
        - 8080

networks:
  backbone:
    driver: bridge

nginx.conf nodejs:8080. - ip.

+4

Source: https://habr.com/ru/post/1652824/


All Articles