Docker CentOS 설치
728x90

Docker 에 CentOS를 설치하는 방법

환경
OS : Window

1. CMD

docker pull centos        => 최신 버전이 다운로드 된다.

2. docker container 생성 및 실행

docker run --name <container-name> centos

하지만 docker 에서 centos 컨테이너를 만들어서 systemctl을 실행하면 이런 에러가 나온다.

이 문제는 가상화 시스템에 나오는 문제인데 정확한 원인은 아직 잘 모른다. centos 이미지를 다운받을 때 systemctl이 되는 버전으로 다운을 받거나 아니면 밑에 나오는 옵션으로 실행 시켜주면 된다.

docker run --name <container-name> --privileged -d centos /usr/sbin/init

그 후 컨테이너 실행 시는

docker exec -it <container-name> bash

3. yum 으로 wget 을 설치 후 tomcat7을 설치

wget install

yum install wget

Error 메시지 발생

Failed to set locale, defaulting to C.UTF-8
CentOS Linux 8 - AppStream          
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist

Error메시지

CentOS 8 EOS 로 인해 CentOS 8 Mirror site 가 vault 로 전환되어 Mirror site 를 못 찾아 발생

이 경우 mirror site가 아닌 vault로 변경

3.1 mirror site -> vault

[root@ ~ /]# sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-Linux-*
[root@ ~ /]# sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-Linux-*

3.2 확인

[root@ ~ /]# dnf repolist     #repolist 확인 
repo id                              repo name
appstream                            CentOS Linux 8 - AppStream
baseos                               CentOS Linux 8 - BaseOS
extras                               CentOS Linux 8 - Extras

[root@ ~ /]# cat /etc/yum.repos.d/CentOS-Linux-BaseOS.repo 
# CentOS-Linux-BaseOS.repo
#
# The #mirrorlist system uses the connecting IP address of the client and the
# update status of each mirror to pick current mirrors that are geographically
# close to the client.  You should use this for CentOS updates unless you are
# manually picking other mirrors.
#
# If the #mirrorlist does not work for you, you can try the commented out
# baseurl line instead.

[baseos]
name=CentOS Linux $releasever - BaseOS
#mirrorlist=http://#mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$infra #주석 처리가 됬다.
baseurl=http://vault.centos.org/$contentdir/$releasever/BaseOS/$basearch/os/  #vault로 변경 됨!
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

위와 같이 당장은 해결이 가능하지만 이 해결방법은 보안에 취약하다.

근본적인 해결을 위해서는 다른 배포판(ex. rocky linux 등) 이나 CentOS 8 Stream, RHEL 8 로 전환이 필요하다.

3.3 다른 해결 방법

CentOS 8 을 CentOS 스트림으로 업그레이드 ( 만약 공부목적이 아니라 운영하는 서버나 QA를 하는 서버라면 반드시 백업을 만들어야한다!)

Stream의 저장소를 추가하고 기존 저장소를 제거

1) 레포지토리 파일 설치

centos-release-stream 패키지 설치

dnf install centos-release-stream -y

2) 시스템 업데이트
dnf distro-sync -y         # 모든 로컬 패키지가 업스트림 버전과 동기화 됨.

Error 메시지

[root@~ /]# dnf distro-sync -y
Failed to set locale, defaulting to C.UTF-8
CentOS-Stream - AppStream                                  4.2 MB/s |  21 MB     00:05
CentOS-Stream - Base                                       3.4 MB/s |  22 MB     00:06
CentOS-Stream - Extras                                      37 kB/s |  18 kB     00:00
Error:
 Problem 1: package centos-linux-repos-8-3.el8.noarch requires centos-gpg-keys = 1:8-3.el8, but none of the providers can be installed

이 에러는 아직 찾지 못했지만 에러 메시지가 비슷한 경우를 발견하여 적어 놓는다.

8.3 업그레이드로 centos-release 패키지 버전 번호 변경으로 인해 생긴 Error

해결방법

  1. "dnf distro-sync"
  2. 먼저 "dnf install centos-release"로 centos-release를 업데이트 한다음 "dnf upgrade"로 전체시스템 업그레이드를 진행
  3. dnf distro-sync --allowerasing --nobest

여기서 3번을 진행해 보도록 하겠다.

[root@77912f6c61ff /]# dnf distro-sync --allowerasing --nobest
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:03:42 ago on Wed Apr 27 05:34:14 2022.
Dependencies resolved.
===========================================================================================
 Package                      Arch    Version                      Repository         Size
===========================================================================================
Installing:
 centos-stream-release        noarch  8.5-2.el8                    Stream-BaseOS      22 k
     replacing  centos-linux-release.noarch 8.4-1.2105.el8
     replacing  centos-release-stream.x86_64 8.1-1.1911.0.7.el8
... (중략)

  xkeyboard-config-2.28-1.el8.noarch

Complete!

일단 성공 했다.

3) 재부팅 후 설치된 버전 확인

재부팅

[root@~ /]# reboot

버전 확인

[root@~ /]# cat /etc/centos-release
CentOS Stream release 8

or

[root@~ /]# cat /etc/os-release
NAME="CentOS Stream"
VERSION="8"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Stream 8"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://centos.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux 8"
REDHAT_SUPPORT_PRODUCT_VERSION="CentOS Stream"

다시 yum install 실행

[root@~ /]# yum install wget
Last metadata expiration check: 0:20:49 ago on Wed 27 Apr 2022 05:32:20 AM UTC.
Dependencies resolved.
===========================================================================================
 Package                        Architecture  Version               Repository        Size
===========================================================================================
Installing:
 wget                           x86_64        1.19.5-10.el8         appstream        734 k
Installing dependencies:
 libpsl                         x86_64        0.20.2-6.el8          baseos            61 k
 publicsuffix-list-dafsa        noarch        20180723-1.el8        baseos            56 k

Transaction Summary
===========================================================================================
Install  3 Packages

Total download size: 851 k
Installed size: 2.9 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): libpsl-0.20.2-6.el8.x86_64.rpm                      401 kB/s |  61 kB     00:00
(2/3): publicsuffix-list-dafsa-20180723-1.el8.noarch.rpm   359 kB/s |  56 kB     00:00
(3/3): wget-1.19.5-10.el8.x86_64.rpm                       2.7 MB/s | 734 kB     00:00
-------------------------------------------------------------------------------------------
Total                                                      3.1 MB/s | 851 kB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                   1/1
  Installing       : publicsuffix-list-dafsa-20180723-1.el8.noarch                     1/3
warning: Unable to get systemd shutdown inhibition lock: Unit systemd-logind.service is masked.

  Installing       : libpsl-0.20.2-6.el8.x86_64                                        2/3
  Installing       : wget-1.19.5-10.el8.x86_64                                         3/3
  Running scriptlet: wget-1.19.5-10.el8.x86_64                                         3/3
  Verifying        : wget-1.19.5-10.el8.x86_64                                         1/3
  Verifying        : libpsl-0.20.2-6.el8.x86_64                                        2/3
  Verifying        : publicsuffix-list-dafsa-20180723-1.el8.noarch                     3/3

Installed:
  libpsl-0.20.2-6.el8.x86_64         publicsuffix-list-dafsa-20180723-1.el8.noarch
  wget-1.19.5-10.el8.x86_64

Complete!

wget 으로 tomcat7 설치

설치 위치는 /usr/local 로 한다.

[root@~ /]# wget -P /usr/local/ https://archive.apache.org/dist/tomcat/tomcat-7/v7.0.109/bin/apache-tomcat-7.0.109.tar.gz
--2022-04-27 05:56:27--  https://archive.apache.org/dist/tomcat/tomcat-7/v7.0.109/bin/apache-tomcat-7.0.109.tar.gz
Resolving archive.apache.org (archive.apache.org)... 138.201.131.134, 2a01:4f8:172:2ec5::2
Connecting to archive.apache.org (archive.apache.org)|138.201.131.134|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9656576 (9.2M) [application/x-gzip]
Saving to: ‘/usr/local/apache-tomcat-7.0.109.tar.gz’

apache-tomcat-7.0.109. 100%[===========================>]   9.21M  2.19MB/s    in 4.2s

2022-04-27 05:56:33 (2.19 MB/s) - ‘/usr/local/apache-tomcat-7.0.109.tar.gz’ saved [9656576/9656576]

확인

[root@77912f6c61ff /]# cd /usr/local
[root@77912f6c61ff local]# pwd
/usr/local
[root@77912f6c61ff local]# ls
apache-tomcat-7.0.109.tar.gz  etc    include  lib64    sbin   src
bin                           games  lib      libexec  share

성공...!

이제 이 이후의 일은 압축을 풀고 자바 설치한 뒤 환경변수 설정을 해주면 되기 때문에 자세하게 적지는 않겠다.

 

 

오류 해결 참조 : https://linuxhandbook.com/update-to-centos-stream/

 

728x90

'컨테이너화 vs 가상화 > Docker' 카테고리의 다른 글

Docker 파일 옮기기  (0) 2022.04.24
Docker에 MariaDB 설치 후 적용  (0) 2022.04.24
Docker-compose 로 컨테이너 생성하기  (0) 2022.04.23