img src relative versus absolute path?
How can I configure a dockerized gitlab so that images (and perhaps uploaded files?) use a relative URL vice an absolute path?
Something similar was discussed in gitlab-ce #1551, but I think that problem may have more due to the choice of ports, not the rewriting of HTML to use the docker-based port forwarding.
Basic Config
Docker set up via:
$ docker run --hostname sub.mydomain.com \
--publish 9443:443 --publish 9022:22 \
--name gitlab --restart always \
--volume /srv/gitlab/config:/etc/gitlab \
--volume /srv/gitlab/logs:/var/log/gitlab \
--volume /srv/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:latest
Changes to gitlab.rb
:
external_url 'https://sub.mydomain.com'
gitlab_rails['gitlab_shell_ssh_port'] = 9022
I copied the appropriate SSL certs. From a browser, I navigate to https://sub.mydomain.com:9433 and all works fine. Until ...
I upload an avatar. Logs show it is uploaded correctly. When I reload the page, in the source includes:
<img alt="Profile" class="avatar avatar s36" src="https://sub.mydomain.com/uploads/user/avatar/2/myavatar.png" />
This URL points to the real computer, not the docker container. I expect it to perhaps be
<img alt="Profile" class="avatar avatar s36" src="https://sub.mydomain.com:9443/uploads/user/avatar/2/myavatar.png" />
but since the internal container doesn't know about docker's port forwarding, this is unlikely. Alternatively,
<img alt="Profile" class="avatar avatar s36" src="/uploads/user/avatar/2/myavatar.png" />
This should prepend the main page's scheme://host:port
.
I have read many people recommend the use of virtual hosts, which doesn't apply (I think) in a docker container. Though I've read it discouraged, I tried adding the port to external_url
but the gitlab instance is never reachable.
Possible ways around this, but I haven't figured out which is best or how to implement them:
-
Change the image (possibly file? need to check) URL generation to use relative paths, omitting the
scheme://host
. -
Change gitlab's
external_url
to allow a port number. I am guessing, since this is not already implemented, that this is not-at-all-trivial, so I only suggest it for completeness. (I am not familiar with gitlab internals.) -
Configure gitlab with an "alternate external URL" (that could optionally include the port). I don't like this, as it adds complexity.
-
Add another external proxy (outside of the gitlab docker container) that catches these translations. This seems a bit like a hack to me, patching the symptom and not the cause.
Versions
root@ext:/srv/gitlab# tail -n 1 /etc/lsb-release
DISTRIB_DESCRIPTION="Ubuntu 14.04.3 LTS"
root@ext:/srv/gitlab# docker version
Client version: 1.6.2
Client API version: 1.18
Go version (client): go1.2.1
Git commit (client): 7c8fca2
OS/Arch (client): linux/amd64
Server version: 1.6.2
Server API version: 1.18
Go version (server): go1.2.1
Git commit (server): 7c8fca2
OS/Arch (server): linux/amd64
root@ext:/srv/gitlab# docker exec gitlab dpkg-query -W gitlab-ce
gitlab-ce 8.3.1-ce.1
Results from docker exec gitlab gitlab-ctl show-config
here: gitlab-ctl.conf