Docker - Running nginx as a proxy for Redmine Docker - Running nginx as a proxy for Redmine docker docker

Docker - Running nginx as a proxy for Redmine


Note: I haven't looked at Bukharov Sergey's answer yet, so that may be more elegant.


Here's what I've come up with. I've found 2 methods for achieving the network sharing capability and 1 hack for a Redmine issue that appears when using said methods.

Method 1 (Preferred because it's shorter, but maybe not because it's deprecated?): Container Linking

docker-compose.yaml

version: '2'services:    nginx:        image: nginx        ports:            - "80:80"        volumes:            - ./nginx/nginx.conf:/etc/nginx/nginx.conf        # Method 1: Linking        links:            - redmine    redmine:        image: redmine        # Method 1: Exposing port to linked containers        expose:            - "3000"

nginx.conf

http {    server {        listen 80;# Method 1: Access via alias from link        location /redmine/ {            proxy_pass http://redmine:3000/;        }}

Method 2: Defining a Network

docker-compose.yaml

version: '2'services:    nginx:        image: nginx        ports:            - "80:80"        volumes:            - ./nginx/nginx.conf:/etc/nginx/nginx.conf        # Method 2        networks:            shared_net:                ipv4_address: 172.22.0.4    redmine:        image: redmine        # Method 2        networks:            shared_net:                ipv4_address: 172.22.0.5# Method number 2: Via networksnetworks:    shared_net:        driver: bridge        ipam:            config:                - subnet: 172.22.0.0/16                  gateway: 172.22.0.1

nginx.conf

http {    server {        listen 80;# Method 2: Access via ip address in shared network        location /redmine_networked/ {            proxy_pass http://172.22.0.5:3000/;        }    }}

Redmine Hack: Accessing redmine via a suburl

The above solutions allow for access to Redmine's home page. All the Redmine URLs, though, will point to root (e.g. '/' for home, instead of '/redmine' or '/redmine_networked'). So none of those links will work. If nginx was setup to redirect all '/' urls to Redmine, this would be a non-issue. The following hack assumes that is not the case.

To get Redmine to point to the URLs configured, one will need to edit the config/environment.rb file.

Here's the hack:

 > docker exec -it <redmine_container> bash redmine> cd config# We're going to install vim (this is a hack) redmine> apt-get update  redmine> apt-get install vim redmine> vim environment.rb

Change the following lines at the bottom of your config/environment.rb

Initialize the Rails application Rails.application.initialize!

to

RedmineApp::Application.routes.default_scope = "/redmine" Initialize the Rails application Rails.application.initialize!
redmine> exit> docker restart <redmine> (or just kill other docker process and run docker up again)


You can use nginx proxy containernginx-proxy sets up a container running nginx and docker-gen. docker-gen generates reverse proxy configs for nginx and reloads nginx when containers are started and stopped.

it is more convenient then manual configuration nginx