LoginSignup
0
0

More than 1 year has passed since last update.

$ docker-compose up -d でwordpressが立ち上がってくれなかった時の対処

Posted at

いい加減dockerから逃げないで向き合おうとしたらとても初歩的なところでドツボに嵌ったので記事にしました。
環境はlocalのmacです。docker及びdocker-composeの導入云々は割愛します。

docker-composeに慣れるために、とりあえずwordpressでも立ち上げようと下記サイトに沿って進行していました。
https://docs.docker.jp/compose/wordpress.html

ほぼコピペで以下のようにtest.yaml(これが元凶)を作成。

test.yaml
version: '3'
services:
   db:
     image: mysql:5.7
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: 11451141
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: 41919819
   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     ports:
       - "8000:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: 41919819
volumes:
    db_data:

mysqlのバージョンをlatestにしてしまうと8系のバージョンが入ってきてしまいwordpressがうまく起動しないので注意。

また、depends_onでdbを先に作ってからwordpressのコンテナを上げるようにしましょう。書いた順番で上から順番に起動してくれるわけではないので、起動順を明示的に指定するのはとても大事。

いざコンテナ起動

$ docker-compose up -d
dockertest_mysql_1 is up-to-date
dockertest_wordpress_1 is up-to-date
shuichimomose@:~/tmp/docker_test/wordpress$ docker-compose ps
         Name                       Command               State          Ports
-------------------------------------------------------------------------------------
dockertest_mysql_1       docker-entrypoint.sh mysqld      Up      3306/tcp, 33060/tcp
dockertest_wordpress_1   docker-entrypoint.sh apach ...   Up      0.0.0.0:80->80/tcp

問題なくコンテナが上がった(ように見える)。

アクセスしてみる。

$ curl -I localhost:8000
HTTP/1.1 500 Internal Server Error
Date: Wed, 19 May 2021 06:30:38 GMT
Server: Apache/2.4.38 (Debian)
X-Powered-By: PHP/7.4.19
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Cache-Control: no-cache, must-revalidate, max-age=0
Connection: close
Content-Type: text/html; charset=UTF-8

コンテナは共に起動しているのにアクセスできない状態。。。
500って事はwordpressあるあるのError Establishing a Database Connectionだろうと踏んでyaml見直すも特に問題が見当たらずなんやこれ状態。
いくら調べても埒が明かないので、物は試しでEC2に同じ環境を立ててdocker-compose upしてみる。

[ec2-user@ip-10-1-34-113 ~]$ docker-compose up -d
ERROR:
        Can't find a suitable configuration file in this directory or any
        parent. Are you in the right directory?
        Supported filenames: docker-compose.yml, docker-compose.yaml

おん?macのlocalでは出なかったエラーが出てきた。

っていうか今までファイル指定してなかったじゃん。。。そらそうよってことでとりあえずファイル名をdocker-compose.yamlにして叩いてみる。

[ec2-user@ip-10-1-34-113 ~]$ docker-compose up -d
Creating volume "ec2-user_db_data" with default driver
Pulling db (mysql:5.7)...
5.7: Pulling from library/mysql
69692152171a: Pull complete
1651b0be3df3: Pull complete
951da7386bc8: Pull complete
0f86c95aa242: Pull complete
37ba2d8bd4fe: Pull complete
6d278bb05e94: Pull complete
497efbd93a3e: Pull complete
a023ae82eef5: Pull complete
e76c35f20ee7: Pull complete
e887524d2ef9: Pull complete
ccb65627e1c3: Pull complete
Digest: sha256:a682e3c78fc5bd941e9db080b4796c75f69a28a8cad65677c23f7a9f18ba21fa
Status: Downloaded newer image for mysql:5.7
Pulling wordpress (wordpress:latest)...
latest: Pulling from library/wordpress
69692152171a: Already exists
2040822db325: Pull complete
9b4ca5ae9dfa: Pull complete
ac1fe7c6d966: Pull complete
5b26fc9ce030: Pull complete
3492f4769444: Pull complete
1dec05775a74: Pull complete
9ed895bcea33: Pull complete
bcc491c2ddc4: Pull complete
8469abe55c17: Pull complete
d74704ab90e5: Pull complete
2f6f8b7d4ce2: Pull complete
3407998a353d: Pull complete
310682739bc5: Pull complete
c82f18ace11b: Pull complete
1a3b9d474dbe: Pull complete
97060a6e7f08: Pull complete
61f5c6c4243b: Pull complete
9d18afd88d98: Pull complete
bcca469c6eb9: Pull complete
b2380b04c4de: Pull complete
Digest: sha256:ff331ff27009fa01b72430033dcff3069331325e677cf10d1f1f22b4973e8627
Status: Downloaded newer image for wordpress:latest
Creating ec2-user_db_1 ... done
Creating ec2-user_wordpress_1 ... done
[ec2-user@ip-10-1-34-113 ~]$ curl -I localhost:8000
HTTP/1.1 302 Found
Date: Thu, 20 May 2021 06:10:27 GMT
Server: Apache/2.4.38 (Debian)
X-Powered-By: PHP/7.4.19
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Cache-Control: no-cache, must-revalidate, max-age=0
X-Redirect-By: WordPress
Location: http://localhost:8000/wp-admin/install.php
Content-Type: text/html; charset=UTF-8

お、302だってことでブラウザからアクセスすると問題なくworspressの設定画面に行けた。

macの方でもファイル名を同じく変更して実行、うまくいった。
そりゃファイルを指定しなけりゃいかんよねというお話でした。なんと初歩的なミス。

docker-compose.yaml(yml)以外のファイル名で作成したときは -f でファイルを指定しましょう。

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