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

3 methods to restore table structure from frm file in mysql [recommended]

When mysql is running normally, it is not difficu...

A brief discussion on which fields in Mysql are suitable for indexing

Table of contents 1 The common rules for creating...

No-nonsense quick start React routing development

Install Enter the following command to install it...

Detailed installation process and basic usage of MySQL under Windows

Table of contents 1. Download MySQL 2. Install My...

Native JavaScript to achieve skinning

The specific code for implementing skinning with ...

Detailed example code of mysql batch insert loop

background A few days ago, when I was doing pagin...

JavaScript to implement the aircraft war game

This article shares with you how to use canvas an...

When the interviewer asked the difference between char and varchar in mysql

Table of contents Difference between char and var...

Mount the disk in a directory under Ubuntu 18.04

Introduction This article records how to mount a ...

Vue+webrtc (Tencent Cloud) practice of implementing live broadcast function

Table of contents 1. Live broadcast effect 2. Ste...

Detailed explanation of how to use awk in Linux

Before learning awk, we should have learned sed, ...

Vue implements the browser-side code scanning function

background Not long ago, I made a function about ...