Docker under proxy environment

Uncle Docker.

This time ** "It turns out that the customer's production environment can only go out to the Internet through a proxy !!!" ** A memo to avoid rushing in such a situation.

Install Docker

Assuming Debian / Ubuntu.

Since it is under a proxy environment, I think that the following will not pass normally, but even if you set the environment variable http_proxy etc. with ~ / .bashrc, if you do sudo, the environment variable will not be inherited, so it will not pass as it is.

$ sudo apt-get install docker.io

If you add the -E option to sudo, it will pass if you inherit the environment variables, but it is troublesome to add -E every time, so it is easier to write the apt configuration file as another method.

:/etc/apt/apt.conf.d/00-proxy


Acquire::http::Proxy "http://{HOST}:{port}";
Acquire::https::Proxy "http://{HOST}:{port}";

I think RHEL / CentOS people have a setting method for yum, so please google it appropriately.

Docker Engine If you drop the image with docker pull etc., you need to set the proxy in Docker Engine.

You can simply set the environment variable HTTP_PROXY`` HTTPS_PROXY, but I think most of them are running on Systemd these days, so it's quick to specify the environment variable in the Systemd config file.

/lib/systemd/system/docker.service


[Service]
Environment=HTTP_PROXY=http://{HOST}:{port}
Environment=HTTPS_PROXY=http://{HOST}:{port}

When building a Docker image

Not only when building a Docker image, but if you want to go out to the Internet with ʻapt-get install` etc., you need to set proxy settings for each tool.

Since apt-get, pip, etc. pass through the proxy just by setting the environment variable, set the environment variable for the time being, and support the tools that need to be handled individually. You can specify environment variables in the Dockerfile to set environment variables at build time, but ARG seems to be a good choice.

For example, to specify args in the Docker Compose configuration file, specify the service build option as follows.

docker-compose.yml


  build:
    context: .
    args:
      - http_proxy=http://{HOST}:{port}
      - https_proxy=http://{HOST}:{port}
      - HTTP_PROXY=http://{HOST}:{port}
      - HTTPS_PROXY=http://{HOST}:{port}

Depending on the tool, the corresponding environment variable name may be uppercase or lowercase, so it is better to specify both. (For example, apt-get doesn't recognize even if you specify uppercase HTTP_PROXY)

When the Docker container starts

When starting a container, it is necessary to set a proxy for each tool as in the case of build, so the only thing that can be done other than individual support is to set environment variables.

It is troublesome to specify the environment variable every time the container is started, so if you write ~ / .docker / config.json, it is easier to use the function that automatically sets HTTP_PROXY etc. in the container.

json:~/.docker/config.json


{
  "proxies": {
    "default": {
      "httpProxy": "http://{HOST}:{port}",
      "httpsProxy": "http://{HOST}:{port}"
    }
  }
}

Configure Docker to use a proxy server | Docker Documentation

Other

Those that cannot be handled by environment variables with settings other than Docker (git, curl, boto3, etc.) Googling and setting them individually.

Recommended Posts

Docker under proxy environment
Pip install (Windows) under Proxy environment
When pip fails under proxy environment
docker and PyCharm under proxy on windows
How to use tensorflow under docker environment
Environment construction: GCP + Docker
Proxy server with Docker
How to use pip3 under proxy environment Note
Use AWS SDK for Python (boto) under Proxy environment
Pip install in proxy environment
Prepare python3 environment with Docker
Python environment construction under Windows7 environment
Run eclipse in Docker environment (noVNC)
Build a go environment using Docker
Build Mysql + Python environment with docker
python memo pip under proxy, easy_install
Environment
Build PyPy execution environment with Docker
[Linux] Docker environment construction on Redhat
code-server online environment (5) Launch code-server on Docker
Docker environment update: add Python package
Rebuild Django's development environment with Docker! !! !! !!
Data science environment construction with Docker
[docker] python3.5 + numpy + matplotlib environment construction
Use the pip command under an HTTP proxy environment that requires authentication
Execution of pip command under proxy (memorial)
Build Jupyter Lab (Python) environment with Docker
Use smbus with python3 under pyenv environment
Using venv in Windows + Docker environment [Python]
How to create an NVIDIA Docker environment
I created an Anaconda environment using Docker!
Create Python + uWSGI + Nginx environment with Docker
Created Ubuntu, Python, OpenCV environment on Docker
[Linux] Build a jenkins environment with Docker
Install Python3 using pythonz under macports environment
Introduction to docker Create ubuntu environment in ubuntu
Use WebDAV in a Portable Docker environment
Build NGINX + NGINX Unit + MySQL environment with Docker
[Linux] Build a Docker environment with Amazon Linux 2