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.
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}
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 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
Those that cannot be handled by environment variables with settings other than Docker (git, curl, boto3, etc.) Googling and setting them individually.
Recommended Posts