Home > Mobile >  Why nginx-based docker image refuses connection in VSCode devcontainer
Why nginx-based docker image refuses connection in VSCode devcontainer

Time:07-16

Consider following setup:

devcontainer.json

{
  "name": "Deputy devcontainer",
  "dockerComposeFile": "docker-compose.yml",
  "service": "go-development",
  "settings": {
    "go.toolsManagement.checkForUpdates": "local",
    "go.useLanguageServer": true,
    "go.gopath": "/go"
  },
  "extensions": [
    "golang.Go",
    "gitlab.gitlab-workflow",
    "GitHub.copilot",
    "eamodio.gitlens",
    "zxh404.vscode-proto3",
    "bungcip.better-toml"
  ],
  "workspaceFolder": "/workspace",
  "remoteUser": "vscode"
}

docker-compose.yml

version: '3'

services:
  go-development:
    image: my-custom-docker-repository/go-development:latest
    command: /bin/sh -c "while sleep 1000; do :; done"
    volumes:
      - ..:/workspace:cached
      - ./deputy-cli-configuration.toml:/home/vscode/.deputy/configuration.toml
    user: vscode

  deputy-package-server:
    image: my-custom-docker-repository/deputy-package-server:latest
    ports:
      - "8080:8080"
    volumes:
      - ./deputy-packages:/var/opt/deputy/deputy-package-server/package
      - ./deputy-repository:/var/opt/deputy/deputy-package-server/repository
    environment:
      - RUST_LOG=debug

  index-repository:
    image: my-custom-docker-repository/deputy-repository-server
    volumes:
      - ./deputy-repository/.git:/srv/git/index.git
    ports:
      - "8082:80"

Dockerfile for index-repository:

FROM teamfruit/nginx-fcgiwrap

RUN apt-get update && apt-get upgrade -y
RUN apt-get install git-core fcgiwrap -y
COPY nginx.conf /etc/nginx/conf.d/default.conf

nginx.conf in index-repository:

server {
    listen       80;

    location ~ /git(/.*) {
        client_max_body_size            0;

        fastcgi_param SCRIPT_FILENAME     /usr/lib/git-core/git-http-backend;
        include       fastcgi_params;

        fastcgi_param   GIT_HTTP_EXPORT_ALL   "";
        fastcgi_param   GIT_PROJECT_ROOT    /srv/git;
        fastcgi_param   PATH_INFO           $1;
        fastcgi_pass   unix:/var/run/fcgiwrap.socket;
    }
}

Dockerfile for go-development:

FROM vscode/devcontainers/go

RUN apt-get update && apt-get upgrade -y
RUN apt-get install protobuf-compiler make debhelper dpkg-dev -y
RUN go install google.golang.org/grpc/cmd/[email protected]
RUN go install google.golang.org/protobuf/cmd/[email protected]
RUN chmod 777 -R /go/pkg

When running the vscode-devcontainer, it is impossible to git clone http://index-repository/git/index.git, this fails with connection refused.

connection-refused-image

However, when I try to clone either directly in the index-repository or host machine, the commands succeeds. Also connecting to deputy-package-server (a simple Rust web-server) works without any issues.

successful-clone-inside-docker-machine

I can also see from the tcpdump that the request actually reaches the nginx-container:

enter image description here

I also used dig to verify that dns is not a problem.

enter image description here

As of right now I am really puzzled as to why the connection keeps getting refused. I am suspecting that the issue may lie somewhere in the nginx configuration, but cannot tell where. What am I doing wrong?

CodePudding user response:

You are mapping the port "8082:80", so you should access the index-repository container by http://localhost:8082 isntead of http://index-repository:8082.

If you want to access the repositroy server container by the domain name index-repository, you should expose the port 80 of the repositroy server container (the hostname would be defaulted in the docker network as same as the service id, eg. index-repository).

Then your dev container can access it as http://index-repository:80

  • Related