docker composeのインストールと動作確認

docker-compose

Raspberry Pi4を購入して最終目標はkubernetesの動作環境を作ろうといろいろと試している筆者です。前回までにdockerを使えるようにしました。dockerが使えるようになったらdocker-composeも使ってみたくなります。

今回の記事はdocker-composeのインストールと動作確認までを試してみます。

では、記事です。

筆者の動作確認環境

この記事で使用している動作確認環境は下記のとおりです。

・H/W :Raspberry Pi 4 Model B 8GB
・OS  :ubuntu-20.04.3

docker-composeのインストール(失敗版)

docker−composeのインストールをしようとまずは公式のサイトを参考に下記のコマンドを試してみました。

$ sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
$ docker-compose --version
/usr/local/bin/docker-compose: line 1: Not: command not found     # ファイルがからでダウンロードできませんでした。

RaspberryPiですがOSにUbuntuを採用しているので「Linux」のインストール手順を参考にしました。しかし、上記のコマンドの結果を見てもらっても分かる通り「line 1: Not: command not found」となってしまいます。

原因は1つ目のcurlコマンドでファイルをダウンロードできなかったためでした。いろいろ調べていると下記のサイトでLinuxでもうまく行かない場合があると書かれていました。

 

docker-compseのインストール(多分成功?!)

インストール失敗版で参考にさせていただいた記事のリンクにdocker/composeのリンクがありましたので、それを参考に作業をしてみました。

docker-composeのgithubのサイトのトップページの中段あたりににあるリンクをクリックします。(下図参照のこと)
docker-compse top

docker-composeのバイナリをダウンロードします。私の場合、本記事の冒頭に書いてあるとおりRashpberryPi を使用していますので「 docker-compose-linux-armv6」をダウンロードしました。

Docker-compose-release

上図はブラウザですが実際にはリンクのURLをコピーしてRashpberryPiのコマンドでwgetしています。

$ wget https://github.com/docker/compose/releases/download/v2.3.3/docker-compose-linux-armv6

ダウンロードが完了したら/usr/local/bin/docker-composeに配置し、コマンド実行できるようにしました。

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

ダウンロードおよび配置が完了したら動作確認も。
$ docker-compose --vserion
Docker Compose version v2.3.3
バージョンが表示されればOKです。私が試したときはv2.3.3が最新でしたので上記が出ればOKだと思います。

docker-composeで複数コンテナを動作させてみる。

docker-composeで複数のコンテナを動作させてみます。
wordpressとmysqlのコンテナを利用します。適当なファイル名をつけて保存します。
version: '3.1'

services:

  wordpress:
    image: "wordpress:latest"
    restart: always
    ports:
      - 8080:80
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: exampleuser
      WORDPRESS_DB_PASSWORD: examplepass
      WORDPRESS_DB_NAME: exampledb
    volumes:
      - wordpress:/var/www/html

  db:
    image: "mysql:oracle"
    restart: always
    environment:
      MYSQL_DATABASE: exampledb
      MYSQL_USER: exampleuser
      MYSQL_PASSWORD: examplepass
      MYSQL_RANDOM_ROOT_PASSWORD: '1'
    volumes:
      - db:/var/lib/mysql

volumes:
  wordpress:
  db:

RaspberryPiを利用しているのでimageはイメージ名の指定だけだと「arm64」用のイメージがない場合があるので、必ずタグまでしたほうが良さそうです。

docker-composeでコンテナを起動する前に、wordpressとmysqlのイメージをpullしておきます。

$ docker pull wordpress:latest
$ docker pull mysql:oracle

imageをpullできたらdocker-composeでコンテナを起動します。

$ docker-compose -f sample.yml up
[+] Running 4/4
⠿ Volume "cli-plugins_wordpress" Created 0.0s
⠿ Volume "cli-plugins_db" Created 0.0s
⠿ Container cli-plugins-db-1 Created 0.5s
⠿ Container cli-plugins-wordpress-1 Created 0.5s
Attaching to cli-plugins-db-1, cli-plugins-wordpress-1
cli-plugins-db-1 | 2022-03-12 02:22:07+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.28-1.el8 started.
cli-plugins-wordpress-1 | WordPress not found in /var/www/html - copying now...
cli-plugins-db-1 | 2022-03-12 02:22:07+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
cli-plugins-db-1 | 2022-03-12 02:22:07+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.28-1.el8 started.
cli-plugins-db-1 | 2022-03-12 02:22:08+00:00 [Note] [Entrypoint]: Initializing database files
cli-plugins-db-1 | 2022-03-12T02:22:08.195095Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.28) initializing of server in progress as process 42
cli-plugins-db-1 | 2022-03-12T02:22:08.262318Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
cli-plugins-wordpress-1 | Complete! WordPress has been successfully copied to /var/www/html
cli-plugins-wordpress-1 | No 'wp-config.php' found in /var/www/html, but 'WORDPRESS_...' variables supplied; copying 'wp-config-docker.php' (WORDPRESS_DB_HOST WORDPRESS_DB_NAME WORDPRESS_DB_PASSWORD WORDPRESS_DB_USER)
cli-plugins-wordpress-1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.3. Set the 'ServerName' directive globally to suppress this message
cli-plugins-wordpress-1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.3. Set the 'ServerName' directive globally to suppress this message
cli-plugins-wordpress-1 | [Sat Mar 12 02:22:09.338458 2022] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.52 (Debian) PHP/7.4.28 configured -- resuming normal operations
cli-plugins-wordpress-1 | [Sat Mar 12 02:22:09.338618 2022] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
cli-plugins-wordpress-1 | 192.168.192.8 - - [12/Mar/2022:02:22:13 +0000] "POST /wp-admin/admin-ajax.php HTTP/1.1" 200 716 "http://192.168.192.201:8080/wp-admin/theme-install.php?search=cocoon" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36"
cli-plugins-db-1 | 2022-03-12T02:22:13.761630Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
cli-plugins-db-1 | 2022-03-12T02:22:29.269879Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
cli-plugins-db-1 | 2022-03-12 02:22:40+00:00 [Note] [Entrypoint]: Database files initialized
cli-plugins-db-1 | 2022-03-12 02:22:40+00:00 [Note] [Entrypoint]: Starting temporary server
cli-plugins-db-1 | 2022-03-12T02:22:41.060050Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.28) starting as process 91
cli-plugins-db-1 | 2022-03-12T02:22:41.121379Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
cli-plugins-db-1 | 2022-03-12T02:22:42.012739Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.

RaspberryPiのIPアドレス:8080でアクセスしてみてwordpressの画面がでることを確認します。下図の画面が表示されれば一旦OKかなと思います。

wordpress-initial-top

 

まとめ

RashpberryPiかつubuntuを使っていると色々とトラップがあってすんなりとは行きませんでしたが色々勉強できてよかったかなと。

 

コメント

タイトルとURLをコピーしました