0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

docker-composeをコマンドラインでインストールする

Posted at

導入

AWSのEC2インスタンスにdocker-composeをインストールしたいと思ったがこれまでDocker Desktopしか使ったことがなく勝手にインストールされていた。やってみようと思ったときに手間取ったので備忘録的に残す。

環境

  • Amazon Linux 2023
$ bash --version
GNU bash, version 5.2.15(1)-release (x86_64-amazon-linux-gnu)

方法

公式のREADMEのWhere to get Docker Composeには以下の手順が記載されている。

You can download Docker Compose binaries from the release page on this repository.

Rename the relevant binary for your OS to docker-compose and copy it to $HOME/.docker/cli-plugins

Or copy it into one of these folders to install it system-wide:

/usr/local/lib/docker/cli-plugins OR >/usr/local/libexec/docker/cli-plugins
/usr/lib/docker/cli-plugins OR /usr/libexec/docker/cli-plugins
(might require making the downloaded file executable with chmod +x)

GitHubのrelease pageからバイナリをダウンロードする。
公式ではインストール先が限定されているように書かれているが実際には別の場所でもよい。今回は/usr/local/bin/docker-composeフォルダにダウンロードする。
ダウンロードにはcurlコマンドを使用する。

$ sudo curl -L https://github.com/docker/compose/releases/download/v.2.29.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

curl -Lはリダイレクトを有効にするオプションである。-oオプションはレスポンスをファイルとして書き出すためのオプションである。

今回の環境の場合uname -suname -mの実行結果は下記になる。
明示的に書いてもいい。

$ uname -s
Linux
$ uname -m
x86_64

次にバイナリをダウンロードしたフォルダに実行権限を付与する。
ここは公式のREADMEに則る。

(might require making the downloaded file executable with chmod +x)

$ sudo chmod +x /usr/local/bin/docker-compose

chmod +xは指定したフォルダに実行権限を付与する。+が権限を追加を表し、xが実行権限を表す。

最後にdocker-composeを実行できるか確認をする。バージョンが表示されたらOK。

$ docker-compose --version
Docker Compose version v2.29.1
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?