5

I am running an ASP.NET Core 3.0 multi-container application on an Azure Linux App Service for Containers using Docker Compose. Containers are built and pushed to an Azure Container Registry via CI pipelines and CD pipelines deploy to the app service using a "docker-compose.[environment].yml".

I am trying to use nginx and jwilder's docker-gen as a reverse proxy (separate containers to avoid having the docker socket bound to a publicly exposed container service), and use virtual host names to access the various services over the net.

I seem to be going round in circles between the following 3 errors:

1. The web app displaying the 'Welcome to Nginx' page with logs repeating:

2020-02-26T15:18:44.021444322Z 2020/02/26 15:18:44 Watching docker events

2020-02-26T15:18:44.022275908Z 2020/02/26 15:18:44 Error retrieving docker server info: Get http://unix.sock/info: dial unix /tmp/docker.sock: connect: no such file or directory

2020-02-26T15:18:44.022669201Z 2020/02/26 15:18:44 Error listing containers: Get http://unix.sock/containers/json?all=1: dial unix /tmp/docker.sock: connect: no such file or directory

2020-02-26T15:18:44.405594944Z 2020/02/26 15:18:44 Docker daemon connection interrupted

2. 502 Bad Gateway

502 - Web server received an invalid response while acting as a gateway or proxy server. There is a problem with the page you are looking for, and it cannot be displayed. When the Web server (while acting as a gateway or proxy) contacted the upstream content server, it received an invalid response from the content server.

3. The app service's 'Application Error :(' page.

Here is my docker-compose.development.yml:

version: "3.7"

services:
  nginx:
    image: nginx
    environment:
      DEFAULT_HOST: ***.azurewebsites.net
    ports:
      - "80:80"
    volumes:
      - "${WEBAPP_STORAGE_HOME}/tmp/nginx:/etc/nginx/conf.d"

  dockergen:
    image: jwilder/docker-gen
    command: -notify-sighup nginx -watch /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
    volumes_from:
      - nginx
    volumes:
      - "/var/run/docker.sock:/tmp/docker.sock:ro"
      - "${WEBAPP_STORAGE_HOME}./nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl"

  webapp:
    image: ***.azurecr.io/digitalcore:dev
    restart: always
    environment:
      VIRTUAL_HOST: ***.azurewebsites.net
    depends_on:
      - nginx

"webapp" service dockerfile (exposes ports 80, 443):

FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build
WORKDIR /source

COPY . .
RUN dotnet restore

RUN dotnet publish --output /app/ --configuration Release --no-restore

FROM mcr.microsoft.com/dotnet/core/aspnet:3.0 AS runtime
WORKDIR /app
COPY --from=build /app .

EXPOSE 80 443
ENTRYPOINT ["dotnet", "DigitalCore.WebApp.dll"]

Error #1 seems to be the closest I have got to seeing it working, with the issues being centred around configuring the volumes correctly for an Azure Linux App Service (the ${WEBAPP_STORAGE_HOME} made an appearance after much digging).

Networks and Container Names only seemed to make things worse in my efforts so far, so they were removed to try and keep things to the bare essentials to get it working. The "webapp" service is where my focus is at the moment

Can anybody spot where I'm going wrong?! I will be eternally grateful for any words of wisdom...

UPDATE:

Some progress it would seem - after removing the "ro" permissions from the container volume, docker.sock is now being found, but docker-gen is unable to connect to the endpoint.

2020-02-26T22:21:44.186316399Z 2020/02/26 22:21:44 Watching docker events

2020-02-26T22:21:44.187487428Z 2020/02/26 22:21:44 Error retrieving docker server info: cannot connect to Docker endpoint

2020-02-26T22:21:44.188270247Z 2020/02/26 22:21:44 Error listing containers: cannot connect to Docker endpoint

2020-02-26T22:21:44.500471940Z 2020/02/26 22:21:44 Docker daemon connection interrupted

UPDATE 2

I have now built the containers and pushed to the Azure Container Registry so I am not pulling from different locations. This is my current docker-compose:

version: "3.7"

services:
  nginx:
    image: ***.azurecr.io/nginx:dev
    ports:
      - "80:80"
    volumes:
      - "${WEBAPP_STORAGE_HOME}/etc/nginx/conf.d"

  dockergen:
    image: ***.azurecr.io/dockergen:dev
    privileged: true
    command: -notify-sighup nginx -watch -only-exposed /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
    volumes_from:
      - nginx
    volumes:
      - "${WEBAPP_STORAGE_HOME}/var/run/docker.sock:/tmp/docker.sock"
      - "${WEBAPP_STORAGE_HOME}./nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl"

  webapp:
    image: ***.azurecr.io/digitalcore:dev
    restart: always
    environment:
      VIRTUAL_HOST: ***.azurewebsites.net
    depends_on:
      - nginx

0 Answers0