mattermost-docker icon indicating copy to clipboard operation
mattermost-docker copied to clipboard

Add support for corporate proxy environment

Open Niceplace opened this issue 9 years ago • 7 comments

Hi all,

I'm trying to run the docker-compose installation and I ran into a small problem, I was getting 404 errors on the "apt-get update && apt-get install" and I figured it was because of our beloved proxy again.

Adding ENV variables to the Dockerfiles fixed it :

ENV http_proxy <HTTP_PROXY> ENV https_proxy <HTTPS_PROXY>

Where HTTP_PROXY and HTTPS_PROXY are replaced by the url of the proxy in question. Any ideas how this could be implemented ? I can dig further and provide a PR if this is OK with you guys.

Niceplace avatar Jan 04 '17 22:01 Niceplace

@Niceplace if you are deploying mattermost, you can use auto built images: https://hub.docker.com/r/mattermost/mattermost-prod-app/, https://hub.docker.com/r/mattermost/mattermost-prod-db/, https://hub.docker.com/r/mattermost/mattermost-prod-web/ so that you can get around with your firewall.

Also if you want to build the image but get 404, it might not be your file cause it seems that apt-get reached the remote server, but server returned 404. You could try sometime later. There might be a problem with apt repo mirror at the time you were building your image. (I got those errors sometime as well).

xcompass avatar Jan 31 '17 05:01 xcompass

Hi @xcompass thanks for replying !

Thank you for suggesting the official images from dockerhub, I didn't explore this solution !

However, I do like the flexibility to have the Dockerfiles of each individual component as this repo provides so I will share my solution.

Regarding this :

There might be a problem with apt repo mirror at the time you were building your image. (I got those errors sometime as well).

I thought that as well but the second I configured my proxy the errors went away. I tested multiple times to make sure.

Here's my final configuration that works (for building, that is. I have other problems with SSL but that's out of scope here.)

Interesting note : variables in docker-compose MUST NOT contain dashes "-", they aren't evaluated if its the case. I haven't found documentation for this yet ( I didn't search a lot ).

Interesting note 2 : These variables are used in the build context only. At least that's what I understand from the docker-compose documentation.

docker-compose.yml

  • replace my.proxy.address with actual proxy adress
  • replace 1234 with actual proxy port
  • sproxy stands for https_proxy, I got lazy. I know there is an http address there as well, its because our company doesn't have an https proxy.
version: "2"

services:

  db:
    build:
      context: ./db
      args:
        proxy: "http://my.proxy.address:1234"
        sproxy: "http://my.proxy.address:1234"
        noproxy: "localhost,127.0.0.1,$LOCAL_DOMAIN"
    restart: always
    volumes:
      - /app/docker-volumes/mattermost/postgresql/data:/var/lib/postgresql/data
      - /etc/localtime:/etc/localtime:ro
    environment:
      - MM_USERNAME=mmuser
      - MM_PASSWORD=mmuser_password
      - MM_DBNAME=mattermost

  app:
    build:
      context: ./app
      args:
        proxy: "http://my.proxy.address:1234"
        sproxy: "http://my.proxy.address:1234"
        noproxy: "localhost,127.0.0.1,$LOCAL_DOMAIN"
    links:
      - db:db
    restart: always
    volumes:
      - /app/docker-volumes/mattermost/mattermost/config:/mattermost/config:rw
      - /app/docker-volumes/mattermost/mattermost/data:/mattermost/data:rw
      - /etc/localtime:/etc/localtime:ro

  web:
    build:
      context: ./web
      args:
        proxy: "http://my.proxy.address:1234"
        sproxy: "http://my.proxy.address:1234"
        noproxy: "localhost,127.0.0.1,$LOCAL_DOMAIN"
    ports:
      - "11443:443"
    links:
      - app:app
    restart: always
    volumes:
        # This directory must have cert files
      - /app/docker-volumes/mattermost/mattermost/cert:/cert:ro
      - /etc/localtime:/etc/localtime:ro
    environment:
      - MATTERMOST_ENABLE_SSL=true
      - PLATFORM_PORT_80_TCP_PORT=80

Dockerfile (this is the one for web, but the same method was used for app and db)

Notice the ARG to "import" arguments from Dockerfile, and double quotes after this with ENV to interpret the value as a string (I think ?).

FROM ubuntu:14.04

ARG proxy
ARG sproxy
ARG noproxy

ENV http_proxy="$proxy"
ENV https_proxy="$sproxy"
ENV no_proxy="$noproxy"

RUN apt-get update && apt-get install -y nginx

RUN rm /etc/nginx/sites-enabled/default

COPY mattermost /etc/nginx/sites-available/
COPY mattermost-ssl /etc/nginx/sites-available/
ADD docker-entry.sh /

RUN chmod +x /docker-entry.sh

# You can see the logs using `docker-compose logs web`.
RUN ln -sf /dev/stdout /var/log/nginx/access.log
RUN ln -sf /dev/stderr /var/log/nginx/error.log

# Define working directory.
WORKDIR /etc/nginx

ENTRYPOINT /docker-entry.sh

EXPOSE 80 443

Niceplace avatar Jan 31 '17 14:01 Niceplace

Closing issue because I found a solution.

Niceplace avatar Jan 31 '17 16:01 Niceplace

Thanks @Niceplace for the update and solution.

xcompass avatar Jan 31 '17 19:01 xcompass

Actually, I still believe, this is an issue of either docker, docker-compose or mattermost docker file. I have encountered exactly the same and IMHO, editting the provided files with my company proxy settings is just a workaround but not a proper fix. The docker-compose (or whatever) should take those proxy settings from the system / docker proxy settings.

pe-pan avatar Sep 18 '17 09:09 pe-pan

I cannot connect and restore nuget packages behind proxy.

prisar avatar May 06 '18 07:05 prisar

The fact I need to keep my environment variables input in two seperate places is quite riddiculous. .env content should be present in the sstem right from the beginning of image building.

mszacun avatar Jul 10 '18 11:07 mszacun