How to use local proxy settings in docker-compose

后端 未结 2 1138

I am setting up a new server for our Redmine installation, since the old installation was done by hand, which makes it difficult to update everything properly. I decided to

相关标签:
2条回答
  • 2020-12-30 06:19

    I did a bit more research and seem to have used better key words because I found my solution now. I wanted to share the solution with everyone, in case someone else may ever need it.

    • Create folder for configuring docker service through systemd

      mkdir /etc/systemd/system/docker.service.d

    • Create service configuration file at /etc/systemd/system/docker.service.d/http-proxy.conf and put the following in the newly created file

    [Service]
     # NO_PROXY is optional and can be removed if not needed
     # Change proxy_url to your proxy IP or FQDN and proxy_port to your proxy port
     # For Proxy server which require username and password authentication, just add the proper username and password to the URL. (see example below)
    
     # Example without authentication
     Environment="HTTP_PROXY=http://proxy_url:proxy_port" "NO_PROXY=localhost,127.0.0.0/8"
    
     # Example with authentication
     Environment="HTTP_PROXY=http://username:password@proxy_url:proxy_port" "NO_PROXY=localhost,127.0.0.0/8"
    
    • Reload systemctl so that new settings are read

      sudo systemctl daemon-reload

    • Verify that docker service Environment is properly set

      sudo systemctl show docker --property Environment

    • Restart docker service so that it uses updated Environment settings

      sudo systemctl restart docker

    Now you can execute the docker-compose command on your machine without getting any connection refused error messages.

    0 讨论(0)
  • 2020-12-30 06:32

    For the proxy server which requires username and password for authentication: Apart from adding the credentials in /etc/systemd/system/docker.service.d/http-proxy.conf, as suggested in this answer, I also had to add the same to the Dockerfile. Following is a snippet from the Dockerfile.

    FROM ubuntu:16.04
    
    ENV http_proxy http://username:password@proxy_url:proxy_port
    ENV https_proxy http://username:password@proxy_url:proxy_port
    
    RUN apt-get update \
        && apt-get upgrade -y \
        && apt-get install -y \
        build-essential \
        bla bla bla ...
    
    0 讨论(0)
提交回复
热议问题