質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
Ubuntu

Ubuntuは、Debian GNU/Linuxを基盤としたフリーのオペレーティングシステムです。

WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

Q&A

解決済

1回答

9446閲覧

UbuntuでDockerを使ったWordPress環境を作りたい

KugaNaoyuki

総合スコア36

Ubuntu

Ubuntuは、Debian GNU/Linuxを基盤としたフリーのオペレーティングシステムです。

WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

0グッド

0クリップ

投稿2017/08/25 12:36

編集2017/08/25 13:20

デスクトップUbuntuでWordPressの開発環境を作ろうと思っています。
見様見真似でDockerを使ってみようと思ったのですが

curl: (7) Failed to connect to localhost port 8000: 接続を拒否されました

と接続できずに困っています。ここからどう進めばいいのでしょうか?

#Docker-compose.yml

version: "2" services: wordpress: image: wordpress:latest ports: - "8000:80" restart: always depends_on: - db environment: WORDPRESS_DB_HOST: db:3306 env_file: .env db: image: mysql:latest env_file: .env volumes: - db-data:/var/lib/mysql

~/deb-wordpress以下にこのファイルをおいて

$sudo docker-compose up -d

をしています。

#環境
Ubuntu16.04
Docker version 1.12.6, build 78d1802
docker-compose version 1.15.0, build e12f3b

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

xenbeat

2017/08/26 02:05

デスクトップUbuntuはVM等で構築した仮想環境ですか?
KugaNaoyuki

2017/08/26 10:53

いえ、仮想環境では実行せず単独で動いています。
guest

回答1

0

ベストアンサー

動作確認してみたので参考にどうぞ。

docker-compose.yml作成して実行

sh

1$ docker-compose up -d 2ERROR: yaml.parser.ParserError: while parsing a block mapping 3 in "./docker-compose.yml", line 1, column 1 4expected <block end>, but found '<block mapping start>' 5 in "./docker-compose.yml", line 13, column 2

字下げがおかしいので修正して実行

diff

1--- a/docker-compose.yml 2+++ b/docker-compose.yml 3@@ -10,8 +10,8 @@ services: 4 environment: 5 WORDPRESS_DB_HOST: db:3306 6 env_file: .env 7- db: 8- image: mysql:latest 9- env_file: .env 10- volumes: 11- - db-data:/var/lib/mysql 12+ db: 13+ image: mysql:latest 14+ env_file: .env 15+ volumes: 16+ - db-data:/var/lib/mysql

sh

1$ docker-compose up -d 2ERROR: Couldn't find env file: /home/takamatu/git/x/.env

.envの空ファイル作成して実行

sh

1$ touch .env 2$ docker-compose up -d 3ERROR: Named volume "db-data:/var/lib/mysql:rw" is used in service "db" but no declaration was found in the volumes section.

カレントディレクトのPATH指定修正して実行

diff

1--- a/docker-compose.yml 2+++ b/docker-compose.yml 3@@ -14,4 +14,4 @@ services: 4 image: mysql:latest 5 env_file: .env 6 volumes: 7- - db-data:/var/lib/mysql 8+ - ./db-data:/var/lib/mysql

sh

1$ docker-compose up -d 2Creating network "x_default" with the default driver 3Creating x_db_1 4Creating x_wordpress_1

sh

1$ docker-compose logs 2Attaching to x_wordpress_1, x_db_1 3wordpress_1 | WordPress not found in /var/www/html - copying now... 4wordpress_1 | Complete! WordPress has been successfully copied to /var/www/html 5wordpress_1 | 6wordpress_1 | Warning: mysqli::mysqli(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22 7wordpress_1 | 8wordpress_1 | Warning: mysqli::mysqli(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22 9wordpress_1 | 10wordpress_1 | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known 11wordpress_1 | 12wordpress_1 | 13wordpress_1 | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known 14wordpress_1 | Warning: mysqli::mysqli(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22 15wordpress_1 | 16wordpress_1 | Warning: mysqli::mysqli(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22 17wordpress_1 | 18wordpress_1 | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known 19db_1 | error: database is uninitialized and password option is not specified 20wordpress_1 | 21db_1 | You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD 22 23≪省略≫

MySQL用の環境変数設定して再実行

sh

1$ cat <<EOS > .env 2MYSQL_ALLOW_EMPTY_PASSWORD=yes 3EOS

sh

1$ docker-compose down 2$ sudo rm -rf db-data 3$ docker-compose up -d 4Creating network "x_default" with the default driver 5Creating x_db_1 6Creating x_wordpress_1

sh

1$ docker-compose logs 2Attaching to x_wordpress_1, x_db_1 3wordpress_1 | WordPress not found in /var/www/html - copying now... 4wordpress_1 | Complete! WordPress has been successfully copied to /var/www/html 5wordpress_1 | 6wordpress_1 | MySQL Connection Error: (2002) Connection refused 7wordpress_1 | 8wordpress_1 | Warning: mysqli::mysqli(): (HY000/2002): Connection refused in - on line 22 9wordpress_1 | 10wordpress_1 | MySQL Connection Error: (2002) Connection refused 11wordpress_1 | 12wordpress_1 | Warning: mysqli::mysqli(): (HY000/2002): Connection refused in - on line 22 13wordpress_1 | 14wordpress_1 | Warning: mysqli::mysqli(): (HY000/2002): Connection refused in - on line 22 15wordpress_1 | 16wordpress_1 | MySQL Connection Error: (2002) Connection refused 17wordpress_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.24.0.3. Set the 'ServerName' directive globally to suppress this message 18wordpress_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.24.0.3. Set the 'ServerName' directive globally to suppress this message 19wordpress_1 | [Sat Aug 26 07:33:07.372698 2017] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.10 (Debian) PHP/5.6.31 configured -- resuming normal operations 20wordpress_1 | [Sat Aug 26 07:33:07.372732 2017] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND' 21db_1 | Initializing database 22db_1 | 2017-08-26T07:32:56.726287Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 23db_1 | 2017-08-26T07:32:57.279334Z 0 [Warning] InnoDB: New log files created, LSN=45790 24db_1 | 2017-08-26T07:32:57.368996Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 25db_1 | 2017-08-26T07:32:57.443416Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: c7df0322-8a30-11e7-b1c3-0242ac180002. 26db_1 | 2017-08-26T07:32:57.445561Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 27db_1 | 2017-08-26T07:32:57.445883Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option. 28db_1 | 2017-08-26T07:32:58.678766Z 1 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode. 29db_1 | 2017-08-26T07:32:58.678799Z 1 [Warning] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode. 30db_1 | 2017-08-26T07:32:58.678807Z 1 [Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode. 31db_1 | 2017-08-26T07:32:58.678820Z 1 [Warning] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode. 32db_1 | 2017-08-26T07:32:58.678824Z 1 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode. 33db_1 | 2017-08-26T07:32:58.678832Z 1 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode. 34db_1 | 2017-08-26T07:32:58.678868Z 1 [Warning] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode. 35db_1 | 2017-08-26T07:32:58.678881Z 1 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode. 36db_1 | Database initialized 37db_1 | Initializing certificates 38 39≪省略≫ 40 41db_1 | 2017-08-26T07:33:06.384817Z 0 [Note] Event Scheduler: Loaded 0 events 42db_1 | 2017-08-26T07:33:06.385121Z 0 [Note] mysqld: ready for connections. 43db_1 | Version: '5.7.19' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL) 44db_1 | 2017-08-26T07:33:06.385132Z 0 [Note] Executing 'SELECT * FROM INFORMATION_SCHEMA.TABLES;' to get a list of tables using the deprecated partition engine. You may use the startup option '--disable-partition-engine-check' to skip this check. 45db_1 | 2017-08-26T07:33:06.385135Z 0 [Note] Beginning of list of non-natively partitioned tables 46db_1 | 2017-08-26T07:33:06.406561Z 0 [Note] End of list of non-natively partitioned tables

sh

1$ docker-compose logs wordpress 2Attaching to x_wordpress_1 3wordpress_1 | WordPress not found in /var/www/html - copying now... 4wordpress_1 | Complete! WordPress has been successfully copied to /var/www/html 5wordpress_1 | 6wordpress_1 | MySQL Connection Error: (2002) Connection refused 7wordpress_1 | 8wordpress_1 | Warning: mysqli::mysqli(): (HY000/2002): Connection refused in - on line 22 9wordpress_1 | 10wordpress_1 | MySQL Connection Error: (2002) Connection refused 11wordpress_1 | 12wordpress_1 | Warning: mysqli::mysqli(): (HY000/2002): Connection refused in - on line 22 13wordpress_1 | 14wordpress_1 | Warning: mysqli::mysqli(): (HY000/2002): Connection refused in - on line 22 15wordpress_1 | 16wordpress_1 | MySQL Connection Error: (2002) Connection refused 17wordpress_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.24.0.3. Set the 'ServerName' directive globally to suppress this message 18wordpress_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.24.0.3. Set the 'ServerName' directive globally to suppress this message 19wordpress_1 | [Sat Aug 26 07:33:07.372698 2017] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.10 (Debian) PHP/5.6.31 configured -- resuming normal operations 20wordpress_1 | [Sat Aug 26 07:33:07.372732 2017] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'

http://localhost:8000

wordpress初期画面

投稿2017/08/26 07:41

tkmtmkt

総合スコア1800

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

KugaNaoyuki

2017/08/26 11:52

ありがとうございます。 - - db-data:/var/lib/mysql + - ./db-data:/var/lib/mysql これを行って指示通りに進んだところ、うまく起動しました。
KugaNaoyuki

2017/08/26 17:10

.envについては書き漏れでした、すいません。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問