0

I have some problem when using Docker. My problem is understanding reverse proxy when using docker-compose and this library https://github.com/jwilder/nginx-proxy

so i have 1 Dockerfile like, here :

FROM alpine:latest
COPY requirements.txt /tmp/requirements.txt

RUN apk add --no-cache \
    g++ \
    gcc \
    freetds \
    ca-certificates \
    build-base \
    libc-dev \
    python3 \
    python3-dev \
    unixodbc-dev \
    bash \
    nginx \
    uwsgi \
    uwsgi-python3 \
    supervisor && \
    python3 -m ensurepip && \
    rm -r /usr/lib/python*/ensurepip && \
    pip3 install --no-cache-dir --upgrade --force-reinstall pip setuptools && \
    pip3 install -r /tmp/requirements.txt && \
    rm /etc/nginx/conf.d/default.conf && \
    rm -r /root/.cache

# Copy ODBC Driver
COPY odbc.ini /etc/
COPY odbcinst.ini /etc/

# Copy the Nginx global conf
COPY nginx.conf /etc/nginx/
# Copy the Flask Nginx site conf
COPY flask-site-nginx.conf /etc/nginx/conf.d/
# Copy the base uWSGI ini file to enable default dynamic uwsgi process number
COPY uwsgi.ini /etc/uwsgi/
# Custom Supervisord config
COPY supervisord.conf /etc/supervisord.conf

# Add demo app
COPY ./app /app
# EXPOSE 80

WORKDIR /app

CMD ["/usr/bin/supervisord"]

when i am run

docker build -t name/name . #success
docker run -d --name=container_name -p 80 name/name:latest #success

and i am run

curl -i localhost/page #success

------------ and my problem is understanding when using nginx-proxy ------------------ within port assigned

1 Create docker network name reverse-proxy and run jwilder/nginx-proxy

docker network create --driver bridge reverse-proxy
docker run -d -p 81:80 -p 444:443 \
    --name reverse-proxy \
    --net=reverse-proxy \
    -v /var/run/docker.sock:/tmp/docker.sock:ro \
    jwilder/nginx-proxy

here my docker-compose.yml

version: "3"

services:
  atk-request:
    build: ./_atkrequest                 #path which Dockerfile is exists
    container_name: api-atkrequest        
    restart: always
    networks: 
      - reverse-proxy
    # ports:
    #   - 80:80                            #host:container
    expose:
      - 80
    environment:
      - VIRTUAL_HOST=atkrequest.api.dev  #nginx-proxy host
      - VIRTUAL_PORT=80                  #nginx-proxy port

networks: 
  reverse-proxy:
    external: 
      name: reverse-proxy

then run

docker-compose up -d #success without error

and output docker ps

CONTAINER ID        IMAGE                    COMMAND                  CREATED              STATUS              PORTS                                      NAMES
ca95a0f42de2        atkrequest_atk-request   "/usr/bin/supervisord"   5 seconds ago        Up 3 seconds        80/tcp                                     api-atkrequest
c42a9f9d85b5        jwilder/nginx-proxy      "/app/docker-entrypoâ¦"   About a minute ago   Up About a minute   0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp   reverse-proxy

and when call url with curl error code 503 Service Temporary UnAvailable

curl -i localhost
HTTP/1.1 503 Service Temporarily Unavailable
Server: nginx/1.14.0
Date: Wed, 10 Oct 2018 07:39:09 GMT
Content-Type: text/html
Content-Length: 213
Connection: keep-alive

<html>
<head><title>503 Service Temporarily Unavailable</title></head>
<body bgcolor="white">
<center><h1>503 Service Temporarily Unavailable</h1></center>
<hr><center>nginx/1.14.0</center>
</body>
</html>

then i am stuck here...

thanks ik

Community
  • 1
  • 1
ikwijaya
  • 83
  • 11

1 Answers1

0

jwilder/nginx-proxy generates an Nginx default.conf with entries for each of your containers that have VIRTUAL_HOST defined.

Since you have defined VIRTUAL_HOST=atkrequest.api.dev on one of your containers, the generated default.conf will have something like

# atkrequest.api.dev
upstream atkrequest.api.dev {
    ## Can be connected with "{{dir_name}}_default" network
    # {{dir_name}}_atk-request
    server {{atk-request container ip}}:80;
}
server {
    server_name atkrequest.api.dev;
    listen 80 ;
    access_log /var/log/nginx/access.log vhost;
    location / {
        proxy_pass http://atkrequest.api.dev;
    }
}

But there will nothing configured for localhost because none you of containers have VIRTUAL_HOST=localhost defined. So when you request arrives to nginx-proxy - it responds with 503 as it does not have any configuration for localhost.

If you want to keep nginx-proxy and be able to access atk-request container with localhost - change it's environment variable to VIRTUAL_HOST=localhost. (Overkill technique, as you can simply expose port 80:80 and not use nginx-proxy, but I include it for the explanation)

If you want to access atk-request container with atkrequest.api.dev - simply add 127.0.0.1 atkrequest.api.dev to your /etc/hosts.

Artem Titkov
  • 559
  • 3
  • 12