Reputation: 2685
I'm trying to create Docker container where I need to use apt-get install command. Currently it looks like this:
FROM ubuntu:18.04
RUN apt-get update && apt-get install -y \
build-essential \
cmake
Unfortunately, when I try to build it I'm getting some errors regarding proxy. I am working behind corporate proxy and I'd like my container to work well in such conditions.
I did some reading online and I tired few options:
Option 1
FROM ubuntu:18.04
ENV http_proxy <HTTP_PROXY>
ENV https_proxy <HTTPS_PROXY>
RUN apt-get update && apt-get upgrade
https://stackoverflow.com/a/22184601
Option 2
FROM ubuntu:18.04
ENV http_proxy 'http://corporate_proxy:port'
ENV https_proxy 'http://corporate_proxy:port'
https://stackoverflow.com/a/30252882
Option 3
docker build --build-arg http_proxy=$http_proxy
--build-arg https_proxy=$https_proxy -t mytest_docker .
Based on https://elegantinfrastructure.com/docker/ultimate-guide-to-docker-http-proxy-configuration/
However, none of this options is working and I'm getting always same error:
Err:1 http://archive.ubuntu.com/ubuntu bionic InRelease
Temporary failure resolving 'corporate_proxy'
Err:2 http://security.ubuntu.com/ubuntu bionic-security InRelease
Temporary failure resolving 'corporate_proxy'
Err:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
Temporary failure resolving 'corporate_proxy'
Err:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease
Temporary failure resolving 'corporate_proxy'
Reading package lists...
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic/InRelease Temporary failure resolving 'corporate_proxy'
corporate_proxy is just a placeholder for actual (working) proxy.
I am sure that the proxy address is correct and is working on host system because I can normally download everything. The problem is only with this docker image.
Any suggestion how I can resolve that?
EDIT #1
Based on the answer from @Raoslaw Szamszur I did a bit more debugging. Unfortunately results are still the same.
I have added values to config.json file and restarted daemon. Next I tried one more time doing all of my options with same outcome.
Also I wanted to run just Ubuntu docker using following line:
docker run --name ubunut -it -p <port_http>:<port_http> -p <port_https>:<port_https> ubuntu:18.04
Once it was running apt-get is unable to download anything printing same kind of error as previously.
Also this is how this container looked in list
docker container ls --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e6fdeaec3ad9 ubuntu:18.04 "/bin/bash" 3 minutes ago Up 3 minutes 0.0.0.0:<http_port>-<https_port>-><http_port>-<https_port>/tcp ubunut
Upvotes: 1
Views: 18077
Reputation: 1740
As the problem may be complex I will try to troubleshoot here.
Option 1
Try first to run clean container from ubuntu image and experiment with connecting with proxy. But don't forget to binds the ports:
docker run -dit --name=<conatiner-name> -p <proxy_port>:<proxy_port> ubuntu
It will be easier to debug the problem that way rather than edit Dockerfile and build with each change. After you find a working solution add those changes to Dockerfile or commit it to a new image.
Option 2
Have you tried to add proxy settings in config.json? Because during build image docker actually build inside temp container. This temp build container doesn't have any ports binded thats why it probably cannot communicate with your proxy.
This file can be found under path:
/home/USERNAME/.docker/config.json
Try adding this:
{
"proxies":
{
"default":
{
"httpProxy": "http://corporate_proxy:port",
"httpsProxy": "http://corporate_proxy:port",
"noProxy": "*.test.example.com,.example2.com"
}
}
}
Configure Docker to use a proxy server
It's hard to reproduce this problem for me, I will keep thinking about other possibilities.
Upvotes: 2