少し前に、UbuntuにDockerをインストールする方法に関するガイドを公開しました 。今日は、CentOSLinuxオペレーティングシステムにDockerをインストールする方法を説明します。さらに、マルチコンテナのDockerアプリケーションを定義して実行するためのツールであるDockercomposeをインストールする方法についても説明します。
このガイドはCentOS向けに特別に作成されていますが、このガイドは、Fedora、RHEL、Scientific Linux、openSUSEなどの他のRPMベースのディストリビューションでも同じです。
CentOSにDockerをインストールする
CentOSにDockerをインストールするには、システムが次の最小要件を満たしている必要があります。
- 64ビット アーキテクチャ;
- カーネルのバージョンは3.10である必要があります 以上。
- システムはインターネットに接続されている必要があります。
Dockerのインストールは非常にシンプルで簡単です。
ターミナルを開き、次のコマンドを root
として実行します ユーザー。
# curl -fsSL https://get.docker.com/ | sh
Dockerをインストールした後、次のコマンドを実行してDockerサービスを有効にして開始します。
# systemctl enable docker
# systemctl start docker
次のコマンドを使用して、Dockerサービスが実行されているかどうかを確認します:
# 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 Wed 2017-03-08 14:09:38 IST; 24s ago Docs: https://docs.docker.com Main PID: 1190 (dockerd) Memory: 54.4M CGroup: /system.slice/docker.service ├─1190 /usr/bin/dockerd └─2327 docker-containerd -l unix:///var/run/docker/libcontainerd/d... Mar 08 14:09:35 server1.ostechnix.local dockerd[1190]: time="2017-03-08T14:09:3... Mar 08 14:09:35 server1.ostechnix.local dockerd[1190]: time="2017-03-08T14:09:3... Mar 08 14:09:35 server1.ostechnix.local dockerd[1190]: time="2017-03-08T14:09:3... Mar 08 14:09:36 server1.ostechnix.local dockerd[1190]: time="2017-03-08T14:09:3... Mar 08 14:09:37 server1.ostechnix.local dockerd[1190]: time="2017-03-08T14:09:3... Mar 08 14:09:38 server1.ostechnix.local dockerd[1190]: time="2017-03-08T14:09:3... Mar 08 14:09:38 server1.ostechnix.local dockerd[1190]: time="2017-03-08T14:09:3... Mar 08 14:09:38 server1.ostechnix.local dockerd[1190]: time="2017-03-08T14:09:3... Mar 08 14:09:38 server1.ostechnix.local dockerd[1190]: time="2017-03-08T14:09:3... Mar 08 14:09:38 server1.ostechnix.local systemd[1]: Started Docker Application ... Hint: Some lines were ellipsized, use -l to show in full.
上記のように、Dockerサービスが実行されています!
Dockerのテスト
先に進んで、Dockerが機能しているかどうかをテストしましょう。
これを行うには、次を実行します:
# docker run hello-world
上記のコマンドは、テストDockerイメージをダウンロードし、サンプルの hello_worldを実行します。 コンテナ内のプログラム。
以下のような出力が表示された場合は、おめでとうございます。 DockerはCentOSシステムで正常に動作しています。
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 78445dd45222: Pull complete Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://cloud.docker.com/ For more examples and ideas, visit: https://docs.docker.com/engine/userguide/にアクセスしてください。
Dockerのバージョンを確認するには、次のコマンドを実行します。
# docker version
出力例:
Client: Version: 17.03.0-ce API version: 1.26 Go version: go1.7.5 Git commit: 60ccb22 Built: Thu Feb 23 10:54:03 2017 OS/Arch: linux/amd64 Server: Version: 17.03.0-ce API version: 1.26 (minimum version 1.12) Go version: go1.7.5 Git commit: 60ccb22 Built: Thu Feb 23 10:54:03 2017 OS/Arch: linux/amd64 Experimental: false
それは今のところすべてです。 Dockerを使用する準備が整いました。
DockerComposeのインストール
ドッカー作成 は、マルチコンテナDockerアプリケーションを定義および実行するために使用できるツールです。 Composeでは、Composeファイルを使用してアプリケーションのサービスを構成します。次に、1つのコマンドを使用して、構成からすべてのサービスを作成して開始できます。
次のいずれかの方法を使用してDockerComposeをインストールできます。
方法1:
ターミナルからroot
として次のコマンドを実行します Docker Composeバイナリファイルをダウンロードするユーザー:
# curl -L "https://github.com/docker/compose/releases/download/1.11.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
次に、次のコマンドを使用して、実行可能権限をバイナリに適用します。
# chmod +x /usr/local/bin/docker-compose
方法2:
または、PIPを使用してDockerComposeをインストールすることもできます。 Pipは、Pythonプログラミング言語で記述されたアプリケーションをインストールするために使用されるPythonパッケージマネージャーです。
Arch Linuxとその派生物では、次のコマンドを実行してpipをインストールします。
# sudo pacman -S python-pip
Debian、Ubuntu、Linux Mintの場合:
# sudo apt-get install python-pip
RHEL、Fedora、CentOSの場合:
# sudo yum install python-pip
または、
# sudo dnf install python-pip
SUSE / openSUSEの場合:
# sudo zypper install python-pip
pipをインストールしたら、次のコマンドを実行してdockercomposeをインストールします。次のコマンドは、すべてのLinuxディストリビューションで同じです!
# pip install docker-compose
Docker Composeをインストールした後、次のコマンドでバージョンを確認できます:
# docker-compose --version
以下のような出力が表示されます。
docker-compose version 1.11.2, build dfed245
これで、CentOSにDockerとDockerComposeをインストールする方法がわかりました。 Dockerの使用を開始するには、次の記事をお読みください。
- Dockerの使用を開始する
無料のDocker電子書籍をダウンロードする:
Download - Free eBook: "Docker Containerization Cookbook"
Download - Free Guide: "Understanding Docker"
Download - Free Guide: "What is Docker and Why is it So Popular?"
Download - Free Guide: "Introduction to Docker"
Download - Free Guide: "Docker in Production"
推奨される読み物:
- 実行中のDockerコンテナを自動的に更新する方法
- ctop –Linuxコンテナ用のコマンドライン監視ツール
- Portainer –Dockerを管理する最も簡単な方法
- PiCluster –シンプルなWebベースのDocker管理アプリケーション
- Dockly-ターミナルからDockerコンテナを管理する