Score:0

How to authenticate when connecting to a proxy server inside ubuntu-based docker container?

cl flag

I am building a docker container that should use proxy server when sending HTTP requests. Unfortunately I can't get it to work - I can't authenticate to the proxy from inside the container, even though credentials are correct.

Expected result curl https://api.myip.com returns JSON response with proxy's IP

Actual result: curl https://api.myip.com returns curl: (56) Received HTTP code 407 from proxy after CONNECT

What I tried:

  • setting HTTP_PROXY env variables (same for HTTPS env)
  • adding "Acquire::http::Proxy" string to /etc/apt/apt.conf (same for https)
  • tried different configurations (only ENV, only apt.conf file, both)

What I checked:

  • /etc/apt/apt.conf contains desired lines (provided below)
  • ENVs are set correctly inside the container
  • proxy is working correctly outside the container
  • proxy authentication works correctly (authorization successful) via browser run from outside the container
  • docker networking works properly (no problems when not using proxy)

my apt.conf:

Acquire::http::Proxy "http://<my_login>:<my_pass>@<proxy_ip>:<proxy_port>/";
Acquire::https::Proxy "https://<my_login>:<my_pass>@<proxy_ip>:<proxy_port>/";
Acquire::socks::Proxy "socks://<my_login>:<my_pass>@<proxy_ip>:<proxy_port>/";

my Dockerfile:

from ubuntu:latest

COPY ./rss/apt.conf /apt.conf
ENV HTTP_PROXY=<ip>:<port>
ENV HTTPS_PROXY=<ip>:<port>

RUN apt update && apt install -y curl
RUN cat /apt.conf >> /etc/apt/apt.conf

ENTRYPOINT ["sleep","1000"]

Docker version: Docker version 20.10.8, build 3967b7d

zwets avatar
us flag
I assume you want to set the system-wide http proxy. The `Acquire::http::Proxy` in `apt.conf` does not do this. It merely sets the mirror that `apt` uses.
Jakub Partyka avatar
cl flag
this is useful, thank you. Do you know a way to set proxy credentials for system-wide configuration?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.