0

I'm trying to run sonatype/nexus3 behind jwilder/nginx-proxy with the idea of using it as maven and docker private repo. I'd like to get nginx proxying nexus subdomain to port 8081 of the nexus container and proxying docker subdomain to port 8082 of the same container. Is this possible?

I first, I made the maven part work without problems as nexus.mydomain.com over TSL using Let's Encrypt certificates:

docker run --restart=always --name nginx -d -p 80:80 -p 443:443 -v /root/certs/:/etc/nginx/certs -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy

docker run --restart=always -d -p 8081:8081 --name nexus -e VIRTUAL_HOST=nexus.mydomain.com -v /root/nexus-data:/nexus-data sonatype/nexus3

Then I realized that to get a docker private repository running I needed to use an additional port. So I created the docker repo on port 8082 and recreated the container using the saved configuration, exposing the new port and with an additional subdomain:

docker run --restart=always -d -p 8081:8081 -p 8082:8082 --name nexus -e VIRTUAL_HOST=nexus.mydomain.com,docker.mydomain.com -v /root/nexus-data:/nexus-data sonatype/nexus3

I have tried overriding nginx configuration mounting a volume on /etc/nginx/vhost.d with no success. Any clues?

Thomasleveil
  • 95,867
  • 15
  • 119
  • 113
Daniel Cerecedo
  • 6,071
  • 4
  • 38
  • 51

1 Answers1

-1

Since jwilder/nginx-proxy works with looping off containers and one port per container. Its a limitaion of jwilder/nginx-proxy rather than docker or docker compose. You can workaround this by creating a socat proxy container which registers domain via ENV and proxy tcp traffic to appropriate port of original container with two http ports.

E.g. Nexus container contains nexus service port + docker registry service port. nginx will now read nexus.example.com -> nexus:5000 registry.example.com -> registry:5000 -> nexus:5000

docker-compose.yml

version: '2'


services:

  nginx:
    image: jwilder/nginx-proxy
    ports:
      - "443:443"
      - "80:80"

  nexus:
    image: sonatype/nexus3
    expose:
      - "8081"
      - "5000"
    environment:
      - VIRTUAL_HOST=nexus.example.com
      - VIRTUAL_PORT=8081
  

  registry:
    image: alpine/socat
    expose:
      - "5000"
    command: TCP4-LISTEN:5000,fork TCP:nexus:5000
    environment:
      - VIRTUAL_HOST=registry.example.com
      - VIRTUAL_PORT=5000
hasnat
  • 2,647
  • 1
  • 20
  • 23