skip to Main Content

I just would like to try to install sshd in centos:latest image.

I try to install ‘passwd’, typing the command like this:

yum install passwd

But I have a error like this:

Failed to set locale, defaulting to C.UTF-8
CentOS-8 - AppStream                            0.0  B/s |   0  B     00:30    
Errors during downloading metadata for repository 'AppStream':
  - Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=container [Could not resolve host: mirrorlist.centos.org]
Error: Failed to download metadata for repo 'AppStream': Cannot prepare internal mirrorlist: Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=container [Could not resolve host: mirrorlist.centos.org]

I don’t know why I can’t install using yum in docker container?

3

Answers


  1. Just tested this on my local machine:

    docker run -it -d --name test centos:latest;
    
    docker exec -it test /bin/bash;
    

    In docker container:

    [root@f3b8b3fe70df /]# yum update -y;
    [root@f3b8b3fe70df /]# yum install passwd;
    
    Login or Signup to reply.
  2. Add access to the host network using --network host

    docker run --network host -it -d --name test centos:latest
    
    Login or Signup to reply.
  3. Masquerading allows for docker ingress and egress:

        firewall-cmd --zone=public --add-masquerade --permanent
    

    Specifically allow incoming traffic on port 80/443 :

         firewall-cmd --zone=public --add-port=443/tcp
    

    Reload firewall to apply permanent rules:

         firewall-cmd --reload
    

    Restart docker :

         systemctl restart docker
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search