简体   繁体   English

如何在部分隔离的主机上的 docker 容器内运行 yum?

[英]How to run yum inside a docker container on a partially isolated host?

I have a machine that is on a semi-isolated network.我有一台位于半隔离网络上的机器。 I have to use proxy to connect to the internet.我必须使用代理连接到互联网。 I have verified that on my host, after I set http_proxy environment variable, I can receive update from public yum repository.我已经验证在我的主机上,设置 http_proxy 环境变量后,我可以从公共 yum 存储库接收更新。

Now I am trying to do the same thing inside a docker container on my machine, but it doesn't seem to work.现在我试图在我机器上的 docker 容器中做同样的事情,但它似乎不起作用。

$docker run --rm -it --net=host rhel /bin/bash
[root@MyCont] http_proxy=http://myproxy:1234/
[root@MyCont] echo -e "[base] \nname=CentOS-7 - Base - centos.com\nbaseurl=http://mirror.centos.org/centos/7/os/\$basearch/\ngpgcheck=1\ngpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7" > /etc/yum.repos.d/CentOS7-Base-centos.repo \
&& yum clean all \
&& yum install -y openssh-server  openssh-clients

I brought up my container in host network mode, so I assume I should have the same network stack as my host in my container.我在主机网络模式下启动了我的容器,所以我假设我应该在我的容器中拥有与我的主机相同的网络堆栈。 Therefore, if I set the http_proxy properly, I should have the same yum behavior inside and outside container.因此,如果我正确设置了 http_proxy,我应该在容器内外具有相同的 yum 行为。

Is it possible to run yum inside a docker container whose host is on a semi-isolated network that needs http_proxy to access yum?是否可以在主机位于需要 http_proxy 访问 yum 的半隔离网络上的 docker 容器中运行 yum?

you should install software inside your image on a build您应该在构建的映像中安装软件

thus use yum install in your dockerfile因此在你的 dockerfile 中使用 yum install

however, if for some reason you need to yum inside the container then ....但是,如果由于某种原因您需要在容器内 yum,那么......

docker run -e http_proxy=http://10.9.2.2:8080

note if yum install isn't working then try ...请注意,如果 yum install 不起作用,请尝试...

yum update

first - for some reason this helps!首先 - 出于某种原因,这有帮助!

also use ...也用...

docker exec -it containerName bash

to enter into the container, then try execute your yum command.进入容器,然后尝试执行你的 yum 命令。 export any proxy env vars as required.根据需要导出任何代理环境变量。

Like danday74 said, you have to use ' export https_proxy=http...'.就像 danday74 说的,你必须使用' export https_proxy=http...'。 Works in my environment.在我的环境中工作。 Just to be safe, I export both http_proxy and https_proxy.为了安全起见,我同时导出了 http_proxy 和 https_proxy。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM