Nginx-proxy only works when using PORTS in docker-compose but not EXPOSE

I’ve got a Nginx-proxy (Jwilder, default config) and Gitlab-Instance running on the same host.
git.myhost.com points to the host IP.
When starting Gitlab with expose: port 8100 like in the docker-compose.yml below I get a 502 Bad Gateway upon accessing http://git.myhost.com. When I expose it through ports it works though.

The generated /etc/nginx/conf.d/default.conf in the nginx-proxy container looks fine as well:

upstream git.myhost.com {
                # 2ab9168d-c69e-4725-8c20-31a194ad8d07
                server 172.17.0.13 vhost;
}
server {
        server_name git.myhost.com;
        listen 80 ;
        access_log /var/log/nginx/access.log vhost;
        location / {
                proxy_pass http://git.myhost.com;
        }
}

What am I doing wrong?

Here’s Gitlab’s docker-compose.yml:

gitlab-server:
  hostname: git.myhost.com
  expose:
  - "8100"
  ports:
  - 8101:22/tcp
#  - 8100:8100/tcp THIS WORKS
  labels:
    io.rancher.sidekicks: gitlab-data
  environment:
    GITLAB_OMNIBUS_CONFIG: |
      external_url 'http://git.myhost.com'
      gitlab_rails['gitlab_shell_ssh_port'] = 8101
    VIRTUAL_HOST: git.myhost.com
    VIRTUAL_PORT: 8100
  image: gitlab/gitlab-ce:latest
  volumes_from:
  - gitlab-data

gitlab-data:
  labels:
    io.rancher.container.start_once: 'true'
  entrypoint:
  - /bin/true
  hostname: gitdata
  image: gitlab/gitlab-ce:latest
  volumes:
  - /etc/gitlab:/etc/gitlab
  - /var/log/gitlab:/var/log/gitlab
  - /var/opt/gitlab:/var/opt/gitlab

It looks like might hit this multiline issue

1 Like

As for your original post, Rancher doesn’t support the expose parameter. If you want something “exposed” on your host, it would have to be moved to the ports section.

1 Like

Maybe 8100 is a typo? In your default.conf you’re listening on 80 not 8100.

I’m not familiar with Gitlab using port 8100. Though, it is possible if you’ve made changes to gitlab.rb. The default ports are at 443, 80, and 22.

In my system, I’m using image: sameersbn/gitlab and VIRTUAL_PORT: '80'. It works as intended.

I think you could update your default.conf to server 172.17.0.13:80 vhost; to redirect from 8100 to 80 but nginx is an area I’m still learning about so I’m not 100% that’ll work. It also would defeat the purpose of using jwilder’s nginx-proxy.