0

I have installed iRedMail on my server which has installed nginx. I have installed docker then gitlab in a docker container.

Is it possible to load balance from the nginx outside docker to the gitlab into the docker container ? I don't know the Ip neither the port.

I also need to use the MariaDB local container with the Gitlab docker container.

Dimitri Kopriwa
  • 13,139
  • 27
  • 98
  • 204

1 Answers1

2

Is it possible to load balance from the nginx outside docker to the gitlab into the docker container ?

You can make automatic updated nginx.conf by using docker-gen

Firstly, install docker-gen on your host by following doc

Then, you should make a docker-gen template to generate your nginx config file.

Assume your gitlab container named gitlab, and we bind it to a domain gitlab.domain.com, then we have this template

{{ range $name, $containers := groupBy $ "Name" }}
{{ $target_name := "gitlab"}}
{{ if $name==$target_name}}
upstream {{ $name }} {

{{ range $index, $value := $containers }}
    {{ with $address := index $value.Addresses 0 }}
    server {{ $address.IP }}:{{ $address.Port }};
    {{ end }}
{{ end }}

}
{{ end }}

server {
    listen 80;
    server_name gitlab.domain.com;

    location / {
        proxy_pass http://{{ $name }};
        include /etc/nginx/proxy_params;
    }
}
{{ end }}

Last, we run docker-gen to automatic generate target nginx config file with

docker-gen -watch -only-exposed -notify "nginx -s reload" nginx.tmpl /etc/nginx/sites-enabled/gitlab.conf


I also need to use the MariaDB local container with the Gitlab docker container.

you can expose host ip to your docker container's host file, here is an answer to do this.

Community
  • 1
  • 1
Freeznet
  • 537
  • 2
  • 6