Docker の仮想環境を使って yum コマンドの練習
yum とは
- yum は RPMパッケージを統合管理するシステム。
- RPM単体でもパッケージ情報や、依存関係の情報を保持しているが管理する機能がないため、それを担うのが yum。
- DebianでのAPTの位置づけになる。
- ディストリビューションのパッケージアップデートやパッケージの検索、追加、削除、情報表示などを行う。
とはいえ、実際に yum コマンドを実行する機会が少なかったりする(自分の開発環境を壊したくない)ので、Docker のイメージを使って試してみたい。
以下、docker はインストール済みが前提で進めていきます。
CentOS 7 のイメージを取得
docker pull コマンドで DockerHub からイメージ取得できます。
今回は公式のイメージを使いますが、あえて旧バージョン7.0を使います。
$ docker pull centos:centos7.0.1406 centos7.0.1406: Pulling from library/centos 1fc5dabcd32d: Pull complete Digest: sha256:e06b6eef24eaf8b531e18691f6d8af5b0610b5b637438be7151930c283b6261f Status: Downloaded newer image for centos:centos7.0.1406
$ docker images | grep centos7 centos centos7.0.1406 59b15a9def8d 2 months ago 210MB
イメージを取得できました。ISOファイルだと4GBあったりするので、それに比べると随分と小さいサイズであることが分かります。
コンテナ作成・起動
コマンド指定無しで実行すると、起動出来なかったので、適当に /bin/bash を付けて起動。
$ docker run -it -d --name centos7 centos:centos7.0.1406 docker: Error response from daemon: No command specified. See 'docker run --help'. $ docker run -it -d --name centos7 centos:centos7.0.1406 /bin/bash 901e2adfc70d0112b37fce72671379c1cb47f1304c1f8be2cdd44b67e1e32680 $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 901e2adfc70d centos:centos7.0.1406 "/bin/bash" 20 seconds ago Up 18 seconds centos7
centos7 という名前のコンテナを作成し起動しました。
bash を起動して、バージョンを確認してみます。
$ docker exec -it centos7 /bin/bash [root@2795a2a189cf /]# cat /etc/redhat-release CentOS Linux release 7.0.1406 (Core)
CentOS の準備が出来ましたので、このコンテナに対して yum コマンドを試行していきます。
yum check-update
リポジトリのアップデートをチェック。
yum check-update Loaded plugins: fastestmirror base | 3.6 kB 00:00:00 extras | 3.4 kB 00:00:00 updates | 3.4 kB 00:00:00 (1/4): base/7/x86_64/group_gz | 166 kB 00:00:00 (2/4): extras/7/x86_64/primary_db | 156 kB 00:00:00 (3/4): updates/7/x86_64/primary_db | 1.3 MB 00:00:02 (4/4): base/7/x86_64/primary_db | 6.0 MB 00:00:06 Determining fastest mirrors * base: ftp.nara.wide.ad.jp * extras: ftp.nara.wide.ad.jp * updates: ftp.nara.wide.ad.jp audit-libs.x86_64 2.8.4-4.el7 base bash.x86_64 4.2.46-31.el7 base binutils.x86_64 2.27-34.base.el7 base bzip2-libs.x86_64 1.0.6-13.el7 base ca-certificates.noarch 2018.2.22-70.0.el7_5 base centos-release.x86_64 7-6.1810.2.el7.centos base --- yum.noarch 3.4.3-161.el7.centos base yum-plugin-fastestmirror.noarch 1.1.31-50.el7 base zlib.x86_64 1.2.7-18.el7 base
アップデート可能なパッケージがたくさん見つかりました。ディストリビューションそのものも(centos-release.x86_64)候補として表示されています。
yum update {package}
1つのパッケージ(ここでは audit-libs)をアップデートしてみます。
# yum update audit-libs.x86_64 Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: ftp.nara.wide.ad.jp * extras: ftp.nara.wide.ad.jp * updates: ftp.nara.wide.ad.jp Resolving Dependencies --> Running transaction check ---> Package audit-libs.x86_64 0:2.3.3-4.el7 will be updated ---> Package audit-libs.x86_64 0:2.8.4-4.el7 will be an update --> Finished Dependency Resolution Dependencies Resolved ================================================================================================================================================================================================== Package Arch Version Repository Size ================================================================================================================================================================================================== Updating: audit-libs x86_64 2.8.4-4.el7 base 100 k Transaction Summary ================================================================================================================================================================================================== Upgrade 1 Package Total download size: 100 k Is this ok [y/d/N]: y Downloading packages: Delta RPMs disabled because /usr/bin/applydeltarpm not installed. warning: /var/cache/yum/x86_64/7/base/packages/audit-libs-2.8.4-4.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY Public key for audit-libs-2.8.4-4.el7.x86_64.rpm is not installed audit-libs-2.8.4-4.el7.x86_64.rpm | 100 kB 00:00:00 Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 Importing GPG key 0xF4A80EB5: Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>" Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5 Package : centos-release-7-0.1406.el7.centos.2.3.x86_64 (@CentOS/$releasever) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 Is this ok [y/N]: y Running transaction check Running transaction test Transaction test succeeded Running transaction Updating : audit-libs-2.8.4-4.el7.x86_64 1/2 Cleanup : audit-libs-2.3.3-4.el7.x86_64 2/2 Verifying : audit-libs-2.8.4-4.el7.x86_64 1/2 Verifying : audit-libs-2.3.3-4.el7.x86_64 2/2 Updated: audit-libs.x86_64 0:2.8.4-4.el7 Complete!
改めて check-update してみると、audit-libs はリストから消えたのが分かります(アップデート済みのため)。
# yum check-update Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: ftp.nara.wide.ad.jp * extras: ftp.nara.wide.ad.jp * updates: ftp.nara.wide.ad.jp bash.x86_64 4.2.46-31.el7 base binutils.x86_64 2.27-34.base.el7 base
yum search {package}
リポジトリからパッケージを検索します。
# yum search wget Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: ftp.nara.wide.ad.jp * extras: ftp.nara.wide.ad.jp * updates: ftp.nara.wide.ad.jp ======================================================================================= N/S matched: wget ======================================================================================== wget.x86_64 : A utility for retrieving files using the HTTP or FTP protocols Name and summary matches only, use "search all" for everything.
"wget" というキーワードに対して、"wget.x86_64" というパッケージが見つかりました。
yum install {package}
リポジトリからパッケージをインストールします。依存関係にあるパッケージも自動的に解決してくれます。
# yum install wget Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: ftp.nara.wide.ad.jp * extras: ftp.nara.wide.ad.jp * updates: ftp.nara.wide.ad.jp Resolving Dependencies --> Running transaction check ---> Package wget.x86_64 0:1.14-18.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================================================================================================================================== Package Arch Version Repository Size ================================================================================================================================================================================================== Installing: wget x86_64 1.14-18.el7 base 547 k Transaction Summary ================================================================================================================================================================================================== Install 1 Package Total download size: 547 k Installed size: 2.0 M Is this ok [y/d/N]: y Downloading packages: wget-1.14-18.el7.x86_64.rpm | 547 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : wget-1.14-18.el7.x86_64 1/1 install-info: No such file or directory for /usr/share/info/wget.info.gz Verifying : wget-1.14-18.el7.x86_64 1/1 Installed: wget.x86_64 0:1.14-18.el7 Complete!
yum info {package}
インストールされているパッケージの情報を表示します。
# yum info wget Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: ftp.nara.wide.ad.jp * extras: ftp.nara.wide.ad.jp * updates: ftp.nara.wide.ad.jp Installed Packages Name : wget Arch : x86_64 Version : 1.14 Release : 18.el7 Size : 2.0 M Repo : installed From repo : base Summary : A utility for retrieving files using the HTTP or FTP protocols URL : http://www.gnu.org/software/wget/ License : GPLv3+ Description : GNU Wget is a file retrieval utility which can use either the HTTP or : FTP protocols. Wget features include the ability to work in the : background while you are logged out, recursive retrieval of : directories, file name wildcard matching, remote file timestamp : storage and comparison, use of Rest with FTP servers and Range with : HTTP servers to retrieve files over slow or unstable connections, : support for Proxy servers, and configurability.
yum list installed
インストールされているパッケージの一覧を表示します。
# yum list installed Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: ftp.nara.wide.ad.jp * extras: ftp.nara.wide.ad.jp * updates: ftp.nara.wide.ad.jp Installed Packages audit-libs.x86_64 2.8.4-4.el7 @base basesystem.noarch 10.0-7.el7.centos @CentOS/$releasever bash.x86_64 4.2.45-5.el7 @CentOS/$releasever --- yum-metadata-parser.x86_64 1.1.4-10.el7 @CentOS/$releasever yum-plugin-fastestmirror.noarch 1.1.31-24.el7 @CentOS/$releasever zlib.x86_64 1.2.7-13.el7 @CentOS/$releasever
yum remove {package}
インストール済みのパッケージを削除します。
インストールしたばかりですが、wget を削除します。
# yum remove wget Loaded plugins: fastestmirror Resolving Dependencies --> Running transaction check ---> Package wget.x86_64 0:1.14-18.el7 will be erased --> Finished Dependency Resolution Dependencies Resolved ================================================================================================================================================================================================== Package Arch Version Repository Size ================================================================================================================================================================================================== Removing: wget x86_64 1.14-18.el7 @base 2.0 M Transaction Summary ================================================================================================================================================================================================== Remove 1 Package Installed size: 2.0 M Is this ok [y/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction install-info: No such file or directory for /usr/share/info/wget.info.gz Erasing : wget-1.14-18.el7.x86_64 1/1 Verifying : wget-1.14-18.el7.x86_64 1/1 Removed: wget.x86_64 0:1.14-18.el7 Complete!
削除されているようです。
# wget --version bash: /usr/bin/wget: No such file or directory
yum repolist all
登録済みのリポジトリ一覧を表示します。
# yum repolist all Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: ftp.nara.wide.ad.jp * extras: ftp.nara.wide.ad.jp * updates: ftp.nara.wide.ad.jp repo id repo name status base/7/x86_64 CentOS-7 - Base enabled: 10019 base-source/7 CentOS-7 - Base Sources disabled centosplus/7/x86_64 CentOS-7 - Plus disabled centosplus-source/7 CentOS-7 - Plus Sources disabled debug/x86_64 CentOS-7 - Debuginfo disabled extras/7/x86_64 CentOS-7 - Extras enabled: 321 extras-source/7 CentOS-7 - Extras Sources disabled updates/7/x86_64 CentOS-7 - Updates enabled: 624 updates-source/7 CentOS-7 - Updates Sources disabled repolist: 10964
登録されていても、無効になっているリポジトリがあります。
yum install {リポジトリ}
リポジトリを追加します。
ここでは、Remi というリポジトリを追加してみます。
# yum install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm Loaded plugins: fastestmirror remi-release-7.rpm | 15 kB 00:00:00 Examining /var/tmp/yum-root-KhJNlg/remi-release-7.rpm: remi-release-7.6-1.el7.remi.noarch Marking /var/tmp/yum-root-KhJNlg/remi-release-7.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package remi-release.noarch 0:7.6-1.el7.remi will be installed --> Processing Dependency: epel-release = 7 for package: remi-release-7.6-1.el7.remi.noarch Loading mirror speeds from cached hostfile * base: ftp.nara.wide.ad.jp * extras: ftp.nara.wide.ad.jp * updates: ftp.nara.wide.ad.jp --> Running transaction check ---> Package epel-release.noarch 0:7-11 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================================================================================================================================== Package Arch Version Repository Size ================================================================================================================================================================================================== Installing: remi-release noarch 7.6-1.el7.remi /remi-release-7 18 k Installing for dependencies: epel-release noarch 7-11 extras 15 k Transaction Summary ================================================================================================================================================================================================== Install 1 Package (+1 Dependent package) Total size: 33 k Total download size: 15 k Installed size: 42 k Is this ok [y/d/N]: y Downloading packages: epel-release-7-11.noarch.rpm | 15 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : epel-release-7-11.noarch 1/2 Installing : remi-release-7.6-1.el7.remi.noarch 2/2 Verifying : remi-release-7.6-1.el7.remi.noarch 1/2 Verifying : epel-release-7-11.noarch 2/2 Installed: remi-release.noarch 0:7.6-1.el7.remi Dependency Installed: epel-release.noarch 0:7-11 Complete!
改めてリポジトリの一覧を見てみると、remi の名前で複数追加されているのが分かります。
主に php 関連のリポジトリであることも明白です。
※remi-safe だけが有効になっていますが、これでOKなのだろうか
# yum repolist all | grep remi * remi-safe: ftp.riken.jp remi Remi's RPM repository for Enterp disabled remi-debuginfo/x86_64 Remi's RPM repository for Enterp disabled remi-glpi91 Remi's GLPI 9.1 RPM repository f disabled remi-glpi92 Remi's GLPI 9.2 RPM repository f disabled remi-glpi93 Remi's GLPI 9.3 RPM repository f disabled remi-glpi94 Remi's GLPI 9.4 RPM repository f disabled remi-php54 Remi's PHP 5.4 RPM repository fo disabled remi-php55 Remi's PHP 5.5 RPM repository fo disabled remi-php55-debuginfo/x86_64 Remi's PHP 5.5 RPM repository fo disabled remi-php56 Remi's PHP 5.6 RPM repository fo disabled remi-php56-debuginfo/x86_64 Remi's PHP 5.6 RPM repository fo disabled remi-php70 Remi's PHP 7.0 RPM repository fo disabled remi-php70-debuginfo/x86_64 Remi's PHP 7.0 RPM repository fo disabled remi-php70-test Remi's PHP 7.0 test RPM reposito disabled remi-php70-test-debuginfo/x86_64 Remi's PHP 7.0 test RPM reposito disabled remi-php71 Remi's PHP 7.1 RPM repository fo disabled remi-php71-debuginfo/x86_64 Remi's PHP 7.1 RPM repository fo disabled remi-php71-test Remi's PHP 7.1 test RPM reposito disabled remi-php71-test-debuginfo/x86_64 Remi's PHP 7.1 test RPM reposito disabled remi-php72 Remi's PHP 7.2 RPM repository fo disabled remi-php72-debuginfo/x86_64 Remi's PHP 7.2 RPM repository fo disabled remi-php72-test Remi's PHP 7.2 test RPM reposito disabled remi-php72-test-debuginfo/x86_64 Remi's PHP 7.2 test RPM reposito disabled remi-php73 Remi's PHP 7.3 RPM repository fo disabled remi-php73-debuginfo/x86_64 Remi's PHP 7.3 RPM repository fo disabled remi-php73-test Remi's PHP 7.3 test RPM reposito disabled remi-php73-test-debuginfo/x86_64 Remi's PHP 7.3 test RPM reposito disabled remi-safe Safe Remi's RPM repository for E enabled: 3097 remi-safe-debuginfo/x86_64 Remi's RPM repository for Enterp disabled remi-test Remi's test RPM repository for E disabled remi-test-debuginfo/x86_64 Remi's test RPM repository for E disabled
基本的なコマンドを一通り叩いてみました。
実際に叩く機会が無いとしても、仮想環境を利用して、色々なコマンドを繰り返し叩いてみることは良い経験になるかもしれません。