Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure docker container proxy?

Tags:

docker

proxy

I am newbie for docker. I try set a proxy for debian:jessie image but i didnt make it. I follow this link . I apply all of them with cat tag (example: 'cat > proxy.sh' , because vi or another editor not installed ) but there is some error about my proxy in apt-get update command.

Error Photo

enter image description here

My proxy : http://username:[email protected]

like image 966
Sinan Barut Avatar asked Dec 15 '17 07:12

Sinan Barut


People also ask

Does Docker need a proxy?

A proxy is required when the server running Docker does not have direct access to the Internet. Configure the Docker daemon to use a proxy server to access images stored on the official Docker Hub Registry or 3rd-party registries.

What is a Docker proxy?

The docker-proxy operates in userland, and simply receives any packets arriving at the host's specified port, that the kernel hasn't 'dropped' or forwarded, and redirects them to the container's port.

What is a container process proxy?

Introduction. ContainerProxy is an application that launches and manages containers for users, to perform specific tasks. Examples include: Run interactive Shiny apps. Execute long-running R jobs.


Video Answer


2 Answers

You can set the proxy environment variables when starting the container, for example:

docker container run \
  -e HTTP_PROXY=http://username:[email protected] \
  -e HTTPS_PROXY=http://username:[email protected] \
  myimage

If you want the proxy-server to be automatically used when starting a container, you can configure default proxy-servers in the Docker CLI configuration file (~/.docker/config.json). You can find instructions for this in the networking section in the user guide.

For example:

{
  "proxies": {
    "default": {
      "httpProxy": "http://username:[email protected]",
      "httpsProxy": "http://username:[email protected]"
    }
  }
}

To verify if the ~/.docker/config.json configuration is working, start a container and print its env:

docker container run --rm busybox env

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=220e4df13604
HTTP_PROXY=http://username:[email protected]
http_proxy=http://username:[email protected]
HTTPS_PROXY=http://username:[email protected]
https_proxy=http://username:[email protected]
HOME=/root
like image 84
thaJeztah Avatar answered Oct 21 '22 16:10

thaJeztah


you need instruct the apt script to connect through proxy inside the container

# echo 'Acquire::http::proxy "proxy:port/";' > /etc/apt/apt.conf.d/40proxy

remember, this should be written inside the container

and in the machine that have docker running, the proxy should be configured like people said before in their comments

like image 4
George Poliovei Avatar answered Oct 21 '22 15:10

George Poliovei