Solution to the error when calling yum in docker container

Solution to the error when calling yum in docker container

When executing yum in dockerfile or in the container, an error is reported and the source cannot be found (invalid baseurl xxx), but there is no problem executing yum on the host machine. Why?

Because no matter whether Dockerfile uses the RUN keyword to execute yum or directly enters the container to execute yum, they all use the source in the Docker image (CentOS is in the path /etc/yum.repo.d/CentOS-Base.repo), so you have to copy the source in the same path on the host machine to the container, and then docker commit a new "base image". At this time, using docker build xxx (that is, using the Dockerfile method) will not report an error.

Copy method: docker cp xxx xxx

Content Extension

Error when executing yum operation in dockerfile

Let’s first look at the error message:

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
The 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.
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
If it is a very temporary problem though, this is often a nice
compromise:

yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

Cannot find a valid baseurl for repo: base/7/x86_64
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=container error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
The command '/bin/sh -c yum install java-1.8.0-openjdk -y' returned a non-zero code: 1

Solution:

You just need to add the DNS service to the resolv.conf file. This file is in /etc. Add

nameserver 8.8.8.8
nameserver 8.8.4.4
search localdomain

That's it

This is the end of this article about how to solve the error when calling yum from a docker container. For more information about how to solve the error when calling yum from a docker container, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Detailed code of the example of downloading the docker installation package from yum and installing it on an offline machine
  • How to configure the docker official source and install docker with yum

<<:  Pure JavaScript to implement the number guessing game

>>:  MySQL uses custom functions to recursively query parent ID or child ID

Recommend

Vue implements tab navigation bar and supports left and right sliding function

This article mainly introduces: using Vue to impl...

Implementation of new issues of CSS3 selectors

Table of contents Basic Selector Extensions Attri...

Native JavaScript to achieve skinning

The specific code for implementing skinning with ...

Examples of some usage tips for META tags in HTML

HTML meta tag HTML meta tags can be used to provi...

Example of creating circular scrolling progress bar animation using CSS3

theme Today I will teach you how to create a circ...

TypeScript Enumeration Type

Table of contents 1. Overview 2. Digital Enumerat...

Express implements login verification

This article example shares the specific code for...

Detailed tutorial on installing and configuring MySql5.7 on Ubuntu 20.04

Table of contents 1. Ubuntu source change 2. Inst...

CentOS6.8 uses cmake to install MySQL5.7.18

Referring to the online information, I used cmake...

Installation of mysql-community-server. 5.7.18-1.el6 under centos 6.5

Use the following command to check whether MySQL ...

Solve the black screen problem after VMware installs Linux system and starts

1. Installation environment 1. HUAWEI mate x cpu ...

The specific use and difference between attribute and property in Vue

Table of contents As attribute and property value...

Docker nginx example method to deploy multiple projects

Prerequisites 1. Docker has been installed on the...