CentOS7 で docker-compose up するまで


何度かやる度に調べていたのでまとめました。
特別な事はしていません。

旧バージョン削除

$ sudo yum -y update
$ sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

Docker Engine インストール

yumリポジトリのセットアップ

$ sudo yum install -y yum-utils \
    device-mapper-persistent-data \
    lvm2
  • yum-utils
    • yum-config-manager がインストールされる
  • device-mapper-persistent-data/ lvm2
    • docker の devicemapper ストレージドライバに必要
$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

で docker の yumリポジトリ追加

$ sudo yum install docker-ce docker-ce-cli containerd.io

完了したら確認

$ docker --version
Docker version 19.03.5, build 633a0ea

サービス起動と自動起動の設定

$ sudo systemctl start docker
$ sudo systemctl enable docker

Docker Compose インストール

なければ curl をインストールしておく

$ sudo yum install -y curl

インストール

$ sudo curl -L https://github.com/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose

確認

$ docker-compose --version
docker-compose version 1.25.4, build 8d51620a

自分を docker グループにいれる。sudo 無しで docker-compose できる様に。
これをやったら一度ログアウト〜再ログインする。

$ sudo usermod -aG docker $USER

確認用の docker-compose.yml 作成。

$ vim docker-compose.yml
version: "3"
services:
  hello:
    image: hello-world:latest

docker-compose up!

$ docker-compose up
Creating network "vagrant_default" with the default driver
Pulling hello (hello-world:latest)...
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:9572f7cdcee8591948c2963463447a53466950b3fc15a247fcad1917ca215a2f
Status: Downloaded newer image for hello-world:latest
Creating vagrant_hello_1 ... done
Attaching to vagrant_hello_1
hello_1  |
hello_1  | Hello from Docker!
hello_1  | This message shows that your installation appears to be working correctly.
hello_1  |
hello_1  | To generate this message, Docker took the following steps:
hello_1  |  1. The Docker client contacted the Docker daemon.
hello_1  |  2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
hello_1  |     (amd64)
hello_1  |  3. The Docker daemon created a new container from that image which runs the
hello_1  |     executable that produces the output you are currently reading.
hello_1  |  4. The Docker daemon streamed that output to the Docker client, which sent it
hello_1  |     to your terminal.
hello_1  |
hello_1  | To try something more ambitious, you can run an Ubuntu container with:
hello_1  |  $ docker run -it ubuntu bash
hello_1  |
hello_1  | Share images, automate workflows, and more with a free Docker ID:
hello_1  |  https://hub.docker.com/
hello_1  |
hello_1  | For more examples and ideas, visit:
hello_1  |  https://docs.docker.com/get-started/
hello_1  |
vagrant_hello_1 exited with code 0

以上です。