はじめに
Oracle CloudでVMを作成し、Dockerをインストールしてみました。
「Oracle Container Cloud Service」を利用すればインストールは不要ですが、
今回は勉強のためにDocker on VM(Linux)でやってみます。
システム環境
Oracle Linux Server 7.9
Dockerインストール
yumでインストール
curlコマンドで最新のDockerパッケージを取得します。
[root@testserver ~]# curl -fsSL https://get.docker.com/ | sh
# Executing docker install script, commit: 7cae5f8b0decc17d6571f9f52eb840fbc13b2737
ERROR: Unsupported distribution 'ol'
[root@testserver ~]#
エラーが出ました。どうやら、Oracle Linux (ol)には対応していない模様。
ではyumを使ってインストールしてみます。
yumリポジトリを作成します。
※Oracle Linux 6の場合、baseurlの末尾が6になるので注意。
[root@testserver ~]# tee /etc/yum.repos.d/docker.repo <<-EOF
> [dockerrepo]
> name=Docker Repository
> baseurl=https://yum.dockerproject.org/repo/main/oraclelinux/7
> enabled=1
> gpgcheck=1
> gpgkey=https://yum.dockerproject.org/gpg
> EOF
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/oraclelinux/7
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
[root@testserver ~]#
[root@testserver ~]# cat /etc/yum.repos.d/docker.repo
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/oraclelinux/7
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
[root@testserver ~]#
yum installコマンドを実行。
[root@testserver ~]# yum install docker-engine
Loaded plugins: langpacks, ulninfo
https://yum.dockerproject.org/repo/main/oraclelinux/7/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: yum.dockerproject.org; Unknown error"
Trying other mirror.
One of the configured repositories failed (Docker Repository),
and yum doesn't have enough cached data to continue. At this point the only
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=dockerrepo ...
4. Disable the repository permanently, so yum won't use it by default. Yum
will then just ignore the repository until you permanently enable it
again or use --enablerepo for temporary usage:
yum-config-manager --disable dockerrepo
or
subscription-manager repos --disable=dockerrepo
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
slower). If it is a very temporary problem though, this is often a nice
compromise:
yum-config-manager --save --setopt=dockerrepo.skip_if_unavailable=true
failure: repodata/repomd.xml from dockerrepo: [Errno 256] No more mirrors to try.
https://yum.dockerproject.org/repo/main/oraclelinux/7/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: yum.dockerproject.org; Unknown error"
[root@testserver ~]#
これもエラー。URLが違うのかな。。。
yum search dockerでパッケージを探してみたら、「ol7_addons/x86_64」リポジトリに既にありました!(最初に確認しておけば良かった。)
[root@testserver ~]# yum search docker
Loaded plugins: langpacks, ulninfo
====================================== N/S matched: docker ======================================
devtoolset-4-docker-client.noarch : Docker Client
devtoolset-4-dockerfiles.x86_64 : Package shipping Dockerfiles for Developer Toolset
devtoolset-4-eclipse-cdt-docker.x86_64 : C/C++ Docker Launcher
devtoolset-4-eclipse-linuxtools-docker.noarch : Docker Tooling
devtoolset-6-dockerfiles.x86_64 : Package shipping Dockerfiles for Developer Toolset
devtoolset-7-dockerfiles.x86_64 : Package shipping Dockerfiles for Developer Toolset
devtoolset-8-dockerfiles.x86_64 : Package shipping Dockerfiles for Developer Toolset
docker-logrotate.x86_64 : cron job to run logrotate on docker containers
docker-registry.noarch : Registry server for Docker
docker-vim.x86_64 : vim syntax highlighting files for docker
docker-zsh-completion.x86_64 : zsh completion files for docker
pcp-pmda-docker.x86_64 : Performance Co-Pilot (PCP) metrics from the Docker daemon
podman-docker.noarch : Emulate Docker CLI using podman
rh-eclipse46-docker-client.noarch : Docker Client
rh-eclipse46-eclipse-cdt-docker.x86_64 : C/C++ Docker Launcher
rh-eclipse46-eclipse-linuxtools-docker.noarch : Docker Tooling
docker.x86_64 : Automates deployment of containerized applications
docker-cli.x86_64 : The open-source application container engine
docker-devel.x86_64 : A golang registry for global request variables (source libraries)
docker-engine.x86_64 : The open-source application container engine
docker-engine-selinux.noarch : SELinux Policies for the open-source application container engine
docker-pkg-devel.x86_64 : A golang registry for global request variables (source libraries)
source-to-image.x86_64 : A tool for building artifacts from source and injecting into docker
: images
Name and summary matches only, use "search all" for everything.
[root@testserver ~]#
ということで、yum install docker-engineコマンドを実行しインストールし成功!
[root@testserver ~]# yum install docker-engine
Loaded plugins: langpacks, ulninfo
Resolving Dependencies
--> Running transaction check
---> Package docker-engine.x86_64 0:19.03.11.ol-11.el7 will be installed
--> Processing Dependency: runc >= 3:1.0.0-1.rc95 for package: docker-engine-19.03.11.ol-11.el7.x86_64
--> Processing Dependency: container-selinux >= 2:2.77 for package: docker-engine-19.03.11.ol-11.el7.x86_64
--> Processing Dependency: containerd for package: docker-engine-19.03.11.ol-11.el7.x86_64
--> Processing Dependency: docker-cli for package: docker-engine-19.03.11.ol-11.el7.x86_64
--> Running transaction check
---> Package container-selinux.noarch 2:2.107-3.el7 will be installed
---> Package containerd.x86_64 0:1.3.9-2.el7 will be installed
---> Package docker-cli.x86_64 0:19.03.11.ol-11.el7 will be installed
---> Package runc.x86_64 3:1.0.0-1.rc95.el7 will be installed
--> Processing Dependency: criu for package: 3:runc-1.0.0-1.rc95.el7.x86_64
--> Running transaction check
---> Package criu.x86_64 0:3.12-2.el7 will be installed
--> Processing Dependency: libprotobuf-c.so.1(LIBPROTOBUF_C_1.0.0)(64bit) for package: criu-3.12-2.el7.x86_64
--> Processing Dependency: libnet.so.1()(64bit) for package: criu-3.12-2.el7.x86_64
--> Processing Dependency: libprotobuf-c.so.1()(64bit) for package: criu-3.12-2.el7.x86_64
--> Running transaction check
---> Package libnet.x86_64 0:1.1.6-7.el7 will be installed
---> Package protobuf-c.x86_64 0:1.0.2-3.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=================================================================================================
Package Arch Version Repository Size
=================================================================================================
Installing:
docker-engine x86_64 19.03.11.ol-11.el7 ol7_addons 21 M
Installing for dependencies:
container-selinux noarch 2:2.107-3.el7 ol7_addons 39 k
containerd x86_64 1.3.9-2.el7 ol7_addons 27 M
criu x86_64 3.12-2.el7 ol7_latest 452 k
docker-cli x86_64 19.03.11.ol-11.el7 ol7_addons 33 M
libnet x86_64 1.1.6-7.el7 ol7_latest 57 k
protobuf-c x86_64 1.0.2-3.el7 ol7_latest 27 k
runc x86_64 3:1.0.0-1.rc95.el7 ol7_addons 3.2 M
Transaction Summary
=================================================================================================
Install 1 Package (+7 Dependent packages)
Total download size: 85 M
Installed size: 349 M
Is this ok [y/d/N]: y
Downloading packages:
(1/8): container-selinux-2.107-3.el7.noarch.rpm | 39 kB 00:00:01
(2/8): criu-3.12-2.el7.x86_64.rpm | 452 kB 00:00:01
(3/8): containerd-1.3.9-2.el7.x86_64.rpm | 27 MB 00:00:02
(4/8): docker-cli-19.03.11.ol-11.el7.x86_64.rpm | 33 MB 00:00:02
(5/8): runc-1.0.0-1.rc95.el7.x86_64.rpm | 3.2 MB 00:00:00
(6/8): docker-engine-19.03.11.ol-11.el7.x86_64.rpm | 21 MB 00:00:01
(7/8): libnet-1.1.6-7.el7.x86_64.rpm | 57 kB 00:00:02
(8/8): protobuf-c-1.0.2-3.el7.x86_64.rpm | 27 kB 00:00:02
-------------------------------------------------------------------------------------------------
Total 15 MB/s | 85 MB 00:00:05
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 2:container-selinux-2.107-3.el7.noarch 1/8
Installing : containerd-1.3.9-2.el7.x86_64 2/8
Installing : libnet-1.1.6-7.el7.x86_64 3/8
Installing : docker-cli-19.03.11.ol-11.el7.x86_64 4/8
Installing : protobuf-c-1.0.2-3.el7.x86_64 5/8
Installing : criu-3.12-2.el7.x86_64 6/8
Installing : 3:runc-1.0.0-1.rc95.el7.x86_64 7/8
Installing : docker-engine-19.03.11.ol-11.el7.x86_64 8/8
xfs_info: cannot open /var/lib: Is a directory
Verifying : 3:runc-1.0.0-1.rc95.el7.x86_64 1/8
Verifying : protobuf-c-1.0.2-3.el7.x86_64 2/8
Verifying : containerd-1.3.9-2.el7.x86_64 3/8
Verifying : docker-cli-19.03.11.ol-11.el7.x86_64 4/8
Verifying : 2:container-selinux-2.107-3.el7.noarch 5/8
Verifying : docker-engine-19.03.11.ol-11.el7.x86_64 6/8
Verifying : criu-3.12-2.el7.x86_64 7/8
Verifying : libnet-1.1.6-7.el7.x86_64 8/8
Installed:
docker-engine.x86_64 0:19.03.11.ol-11.el7
Dependency Installed:
container-selinux.noarch 2:2.107-3.el7 containerd.x86_64 0:1.3.9-2.el7
criu.x86_64 0:3.12-2.el7 docker-cli.x86_64 0:19.03.11.ol-11.el7
libnet.x86_64 0:1.1.6-7.el7 protobuf-c.x86_64 0:1.0.2-3.el7
runc.x86_64 3:1.0.0-1.rc95.el7
Complete!
[root@testserver ~]#
[root@testserver ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Docs: https://docs.docker.com
[root@testserver ~]#
Dockerデーモン起動
Dockerデーモンの自動起動を有効化し、起動します。
[root@testserver ~]# systemctl is-enabled docker
disabled
[root@testserver ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@testserver ~]# systemctl is-enabled docker
enabled
[root@testserver ~]#
[root@testserver ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: inactive (dead)
Docs: https://docs.docker.com
[root@testserver ~]# systemctl start docker
[root@testserver ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2021-07-04 00:50:30 GMT; 2s ago
Docs: https://docs.docker.com
Main PID: 31353 (dockerd)
Tasks: 8
Memory: 49.4M
CGroup: /system.slice/docker.service
└─31353 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Jul 04 00:50:26 testserver dockerd[31353]: time="2021-07-04T00:50:26.134953859Z" level=warn...ht"
Jul 04 00:50:26 testserver dockerd[31353]: time="2021-07-04T00:50:26.135282771Z" level=warn...ce"
Jul 04 00:50:26 testserver dockerd[31353]: time="2021-07-04T00:50:26.135692656Z" level=info...t."
Jul 04 00:50:28 testserver dockerd[31353]: time="2021-07-04T00:50:28.726334011Z" level=info...ss"
Jul 04 00:50:29 testserver dockerd[31353]: time="2021-07-04T00:50:29.716527408Z" level=info...e."
Jul 04 00:50:30 testserver dockerd[31353]: time="2021-07-04T00:50:30.034900804Z" level=warn...ay2
Jul 04 00:50:30 testserver dockerd[31353]: time="2021-07-04T00:50:30.035102925Z" level=info...-ol
Jul 04 00:50:30 testserver dockerd[31353]: time="2021-07-04T00:50:30.036208724Z" level=info...on"
Jul 04 00:50:30 testserver dockerd[31353]: time="2021-07-04T00:50:30.336407573Z" level=info...ck"
Jul 04 00:50:30 testserver systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.
[root@testserver ~]#
インストール確認(nginxのコンテナ起動)
正しくインストールできたか確認するため、nginxのコンテナを起動してみます。
まずはnginxコンテナをpullします。
[root@testserver ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@testserver ~]# docker pull nginx
Using default tag: latest
Trying to pull repository docker.io/library/nginx ...
latest: Pulling from docker.io/library/nginx
b4d181a07f80: Pull complete
edb81c9bc1f5: Pull complete
b21fed559b9f: Pull complete
03e6a2452751: Pull complete
b82f7f888feb: Pull complete
5430e98eba64: Pull complete
Digest: sha256:47ae43cdfc7064d28800bc42e79a429540c7c80168e8c8952778c0d5af1c09db
Status: Downloaded newer image for nginx:latest
nginx:latest
[root@testserver ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 4f380adfc10f 10 days ago 133MB
[root@testserver ~]#
pullが完了したら、nginxコンテナを起動します。
[root@testserver ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@testserver ~]# docker run --name TestNginx -d -p 8080:80 nginx
5cd32821e8cd3f0fab545d222421cffeb713958a0ba1ce15d80816ab52db58ce
[root@testserver ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5cd32821e8cd nginx "/docker-entrypoint.…" 7 seconds ago Up 5 seconds 0.0.0.0:8080->80/tcp TestNginx
[root@testserver ~]#
- –name : 起動するコンテナのイメージ名
- -d : バックグラウンドで実行
- -p : ポートの指定 (<ホスト側のポート番号> : <コンテナ側のポート番号>)
今回はテストサーバなので、firewalldは止めてしまいます。
[root@testserver ~]# systemctl status firewalld
[root@testserver ~]# systemctl stop firewalld
[root@testserver ~]# systemctl status firewalld
また、Oracle Cloudなので、ネットワークセキュリティグループのポート開放も忘れずに行います。
http://<ホストのIPアドレス>:8080/
成功!表示されました!!
今回のまとめ
- 「yum install docker-engine」コマンドでインストール
- 「systemctl is-enabled docker」「systemctl start docker」コマンドでDockerデーモン自動起動有効・起動
- 「docker pull」「docker run」コマンドでコンテナ起動