docker容器调用yum报错的解决办法
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
docker容器调⽤yum报错的解决办法
dockerfile⾥或者在容器⾥执⾏yum,报错,找不到源(invalid baseurl xxx),但是宿主机上执⾏yum是没问题的啊,为什么?
因为不论是dockerfile使⽤RUN关键字执⾏yum还是直接进⼊到容器⾥⾯执⾏yum,它们都是使⽤的docker镜像⾥⾯的源(CentOS是在路径/etc/yum.repo.d/CentOS-Base.repo),所以你要把宿主机上的同路径下的源拷贝到容器⾥⾯,然后docker commit⼀个新的“基础镜像”,这个时候使⽤docker build xxx(即使⽤Dockerfile的⽅式)就不会报错了。
拷贝⽅法docker cp xxx xxx
内容扩展
dockerfile中执⾏yum操作报错
我们先看下报错信息:
Sending build context to Docker daemon 9.363 MB
Step 1 : FROM docker.io/centos
---> 196e0ce0c9fb
Step 2 : MAINTAINER liuliangliang
---> Using cache
---> 7d7e06799c20
Step 3 : ADD file/tomcat7.tgz /usr/local/
---> Using cache
---> 10ffdea53a02
Step 4 : RUN yum install java-1.8.0-openjdk -y
---> Running in 7824a339e077
Loaded plugins: fastestmirror, ovl
One of the configured repositories failed (Unknown),
and yum doesn't have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work "fix" this:
1. Contact the upstream for the repository and get them to fix the problem.
2. Reconfigure the baseurl/etc. for the repository, to point to a working
upstream. This is most often useful if you are using a newer
distribution release than is supported by the repository (and the
packages for the previous distribution release still work).
3. Run the command with the repository temporarily disabled
yum --disablerepo=<repoid> ...
4. Disable the repository permanently, so yum won't use it by default. Yum
will then just ignore the repository until you permanently enable it
again or use --enablerepo for temporary usage:
yum-config-manager --disable <repoid>
or
subscription-manager repos --disable=<repoid>
5. Configure the failing repository to be skipped, if it is unavailable.
Note that yum will try to contact the repo. when it runs most commands,
so will have to try and fail each time (and thus. yum will be be much
slower). If it is a very temporary problem though, this is often a nice
compromise:
yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true
解决⽅法:
这个你在resolv.conf⽂件⾥加上 DNS服务就⾏了这个⽂件在/etc下,加上
nameserver 8.8.8.8
nameserver 8.8.4.4
search localdomain
就⾏了
到此这篇关于docker容器调⽤yum报错的解决办法的⽂章就介绍到这了,更多相关docker容器调⽤yum报错如何解决内容请搜索以前的⽂章或继续浏览下⾯的相关⽂章希望⼤家以后多多⽀持!。