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

Steps to install Pyenv under Deepin

Preface In the past, I always switched Python ver...

CentOS 7 method to modify the gateway and configure the IP example

When installing the centos7 version, choose to co...

Let's talk about the difference between MyISAM and InnoDB

The main differences are as follows: 1. MySQL use...

How to configure MySQL master-slave synchronization in Ubuntu 16.04

Preparation 1. The master and slave database vers...

Deploy Confluence with Docker

1. Environmental requirements 1. Docker 17 and ab...

Detailed explanation of hosts file configuration on Linux server

Linux server hosts file configuration The hosts f...

Steps for Docker to build a private warehouse Harbor

Harbor Harbor is an open source solution for buil...

A Brief Analysis of MySQL PHP Syntax

Let's first look at the basic syntax of the c...

How to use cursor triggers in MySQL

cursor The set of rows returned by the select que...

Common browser compatibility issues (summary)

Browser compatibility is nothing more than style ...

Introduction to deploying selenium crawler program under Linux system

Table of contents Preface 1. What is selenium? 2....

CentOS 8 custom directory installation nginx (tutorial details)

1. Install tools and libraries # PCRE is a Perl l...

Zabbix configures DingTalk's alarm function with pictures

Implementation ideas: First of all, the alarm inf...

MySQL 5.7 mysql command line client usage command details

MySQL 5.7 MySQL command line client using command...