29

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 go with a Docker image but am having trouble starting the docker container due to an error message. The host is running behind a proxy server, which I think, is causing this problem, as everything else such as wget, curl, etc. is working fine.

Error message:

Pulling redmine (redmine:)...
ERROR: Get https://registry-1.docker.io/v2/: dial tcp 34.206.236.31:443: connect: connection refused

I searched on Google about using Docker/Docker-Compose with a proxy server in the background and found a few websites where people had the same issue but none of these really helped me with my problem.

I checked with the Docker documentation and found a guide but this does not seem to work for me: https://docs.docker.com/network/proxy/

I also found an answered question here on StackOverflow: Using proxy on docker-compose in server which might be the solution I am after but I am unsure where exactly I have to put the solution. I guess the person means the docker-compose.yml file but I could be wrong.

This is what my docker-compose.yml looks like:

version: '3.1'

services:

redmine:
 image: redmine
 restart: always
 ports:
   - 80:3000
 environment:
   REDMINE_DB_MYSQL: db
   REDMINE_DB_PASSWORD: SECRET_PASSWORD

db:
image: mysql:5.7
restart: always
environment:
  MYSQL_ROOT_PASSWORD: SECRET_PASSWORD
  MYSQL_DATABASE: redmine

I expect to run the following command without the above error message

docker-compose -f docker-compose.yml up -d

2 Answers 2

54

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

  • Create a folder for configuring the Docker service through systemd

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

  • Create a 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 servers that 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"

 # Example for SOCKS5

Environment="HTTP_PROXY=socks5://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.

5
  • 1
    How can I enter the password for the proxy? Aug 8, 2019 at 7:17
  • 1
    @PrasanthGanesan Depending on the protocol you use, you could use one of the following URLs: http://username:password@proxy_url:proxy_port https://username:password@proxy_url:proxy_port
    – C.Felix
    Aug 9, 2019 at 9:11
  • 2
    Thanks to @PrasanthGanesan for bringing up the username/password authentication. I edited my original post and added an example of such authentication in the http-proxy.conf
    – C.Felix
    Aug 9, 2019 at 14:20
  • 1
    SOCKS5 can also be used: HTTP_PROXY=socks5://proxy_url:proxy_port. May 24, 2022 at 11:38
  • 1
    Please note that the proxy settings need trailing slashes at the end! @see stackoverflow.com/a/71666466/4666528
    – Mel_T
    Nov 30, 2022 at 13:03
10

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 ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.