I am working with Docker with a compose where I have an apache with php, a redmine, a portainer to control the containers and I am installing GitLab.
My problem comes in GitLab since by default it forces me to put a port to access and I would like it to go through a route, but I understand that each container has either its Apache or its Nginx since when I throw Apache and php I can still enter redmine and gitlab. How can I do to access GitLab through a route? I have looked at the VirtualHost issue but being in different Docker I do not know how to tell it where to look for the information.
The main problem is that it forces me to put the port whenever a user tries to recover a password, they get the path without the port or clone a repository and have to put it manually.
Greetings and thank you.
I modify the POST
This is my complete docker-compose. I am new to docker and I am learning with each problem that appears.
version: '2'
services:
php:
container_name: php
restart: always
image: php:7-apache
ports:
- "80:80"
- "443:443"
volumes:
- ./html:/var/www/html
- ./certificados:/etc/ssl/certs
gitlab:
image: 'gitlab/gitlab-ce:latest'
restart: always
hostname: 'localhost'
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://localhost/gitlab'
# Add any other gitlab.rb configuration here, each on its own line
ports:
- '32787:80'
- '32786:443'
- '32788:22'
volumes:
- './config:/etc/gitlab'
- './logs:/var/log/gitlab'
- './data:/var/opt/gitlab'
redmine:
container_name: redmine
restart: always
image: redmine
ports:
- "3000:3000"
volumes:
- ./redmineData:/usr/src/redmine/files
- ./redminePlugins:/usr/src/redmine/plugins
- ./redmineConfig/configuration.yml:/usr/src/redmine/config/configuration.yml
environment:
REDMINE_DB_MYSQL: xx
REDMINE_DB_PASSWORD: xxxxxx
db:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: xxxxx
MYSQL_DATABASE: xxxx
volumes:
- ./mysqlData:/var/lib/mysql
portainer:
image: portainer/portainer
restart: always
ports:
- "9000:9000"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./portainer_data:/data portainer/portainer
my idea would be to be able to enter this way http://localhost/gitlab
and not with the port http://localhost:32787/gitlab so it works. The main problem is when uploading via ssh or recovering the pass, it sends me the mail without the port.
All the best.
edit 01
docker-compose
version: '2'
services:
nginx:
image: nginx:latest
container_name: servidor_nginx
depends_on:
- php
- redmine
volumes:
- ./virtualhost.conf:/etc/nginx/nginx.conf
ports:
- 80:80
- 443:443
php:
container_name: php
restart: always
image: php:7-apache
ports:
- "8080:80"
volumes:
- ./html:/var/www/html
redmine:
container_name: redmine
restart: always
image: redmine
ports:
- "3000:3000"
volumes:
- ./redmineData:/usr/src/redmine/files
- ./redminePlugins:/usr/src/redmine/plugins
- ./redmineConfig/configuration.yml:/usr/src/redmine/config/configuration.yml
environment:
REDMINE_DB_MYSQL: db
REDMINE_DB_PASSWORD: xxxxx
db:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: xxxxx
MYSQL_DATABASE: redmine
volumes:
- ./mysqlData:/var/lib/mysql
portainer:
image: portainer/portainer
restart: always
ports:
- "9000:9000"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./portainer_data:/data portainer/portainer
virtualhost
events {
}
http {
error_log /etc/nginx/error_log.log warn;
client_max_body_size 20m;
proxy_cache_path /etc/nginx/cache keys_zone=one:500m max_size=1000m;
server {
listen 80;
server_name localhost;
location /php {
proxy_pass http://php:8080/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $http_host;
}
location /redmine {
proxy_pass http://redmine:3000/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $http_host;
}
}
}
When I try this route:
http://localhost/redmine gives me 502 Bad Gateway
Add to your docker-compose your nginx server to do the reverse proxy.
First, create your
virtualhost.conf
should be found in the root along with thedocker-compose.yml
:Where in the line
proxy_pass
should be configured as:proxy_pass http://container_name:port_container
the second, in your
docker-compose.yml
add something like: