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?

More than 5 years have passed since last update.

Windows 10 Homeローカル環境でwordpressを30分で起動する with docker

Last updated at Posted at 2019-12-25

自宅のwindows 10 Homeでwordpressを起動してみた
起動はできたが、mariaDBのデータをローカルディレクトリで永続化しようとするとエラーになるのでdocker volumeでの永続化となっている。

環境

Windows 10 Home
1809

必要なものをインストール

chocolatey install
管理者権限で起動したpower shellから以下のコマンドを実行

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

virtual box

choco install virtualbox

docker-toolbox

choco install -y docker-toolbox

cygwin install(ディレクトリ作成のみで使用なのでなくても可)

choco install -y cygwin

手順

docker quick terminalを起動し、dockerの実行可能なVMを起動する

以下基本的にpowershellでコマンドを発行している。

作業ディレクトリを作成する

docker-toolboxで起動するhostのvolumeがC:\Usersにマウントされているのでその配下で作業ディレクトリを作成するのが最速

mkdir -p $env:USERPROFILE\work
cd $env:USERPROFILE\work

docker-compose.ymlを作成する

vi docker-compose.yml

mariadbのバージョンは指定しておいたほうが良いと思われる。
12/26 プラグインが動かなかったのでDNSの設定追加しました。

version: '3.1'

services:

  wordpress:
    image: wordpress
    restart: always
    ports:
      - 8080:80
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: user
      WORDPRESS_DB_PASSWORD: pw
      WORDPRESS_DB_NAME: db_name
    dns:
      - 8.8.8.8
      - 9.9.9.9
    volumes:
      - /c/Users/ユーザー名/work/wordpress:/var/www/html

  db:
    image: mariadb
    restart: always
    environment:
      MYSQL_DATABASE: db_name
      MYSQL_USER: user
      MYSQL_PASSWORD: pw
      MYSQL_RANDOM_ROOT_PASSWORD: '1'
    volumes:
      - db:/var/lib/mysql

volumes:
  db:

起動

docker-compose up -d

コマンドプロンプトからIP確認

docker-machine ip default

ブラウザからアクセス

http://${表示されたIP}:8080/

tips

ログの確認

docker-compose logs -f

バッドノウハウ

mysqlが上がってこないのでmariaDBを使うようにした。

--initialize specified but the data directory has files in it. Aborting.

元のdocker-compose.yml

version: '3.1'

services:

  wordpress:
    image: wordpress
    restart: always
    ports:
      - 8080:80
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: user
      WORDPRESS_DB_PASSWORD: pw
      WORDPRESS_DB_NAME: db_name
    volumes:
      - /c/Users/ユーザー名/work/wordpress:/var/www/html

  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_DATABASE: db_name
      MYSQL_USER: user
      MYSQL_PASSWORD: pw
      MYSQL_RANDOM_ROOT_PASSWORD: '1'
    volumes:
      - /c/Users/ユーザー名/work/db:/var/lib/mysql

mariadbのデータ領域をローカルディレクトリ上で永続化しようとするとエラーになる

db_1         | 2019-12-25  3:57:00 0 [ERROR] InnoDB: Corrupted page [page id: space=0, page number=0] of datafile './ibd
ata1' could not be found in the doublewrite buffer.
db_1         | 2019-12-25  3:57:00 0 [ERROR] InnoDB: Plugin initialization aborted with error Data structure corruption
db_1         | 2019-12-25  3:57:00 0 [ERROR] Plugin 'InnoDB' init function returned error.
db_1         | 2019-12-25  3:57:00 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
db_1         | 2019-12-25  3:57:00 0 [ERROR] Unknown/unsupported storage engine: InnoDB
db_1         | 2019-12-25  3:57:00 0 [ERROR] Aborting
db_1         |
db_1         | Installation of system tables failed!  Examine the logs in
db_1         | /var/lib/mysql/ for more information.
db_1         |
db_1         | The problem could be conflicting information in an external
db_1         | my.cnf files. You can ignore these by doing:
db_1         |
db_1         |     shell> /usr/bin/mysql_install_db --defaults-file=~/.my.cnf
db_1         |
db_1         | You can also try to start the mysqld daemon with:
db_1         |
db_1         |     shell> /usr/sbin/mysqld --skip-grant-tables --general-log &
db_1         |
db_1         | and use the command line tool /usr/bin/mysql
db_1         | to connect to the mysql database and look at the grant tables:
db_1         |
db_1         |     shell> /usr/bin/mysql -u root mysql
db_1         |     mysql> show tables;
db_1         |
db_1         | Try 'mysqld --help' if you have problems with paths.  Using
db_1         | --general-log gives you a log in /var/lib/mysql/ that may be helpful.
db_1         |
db_1         | The latest information about mysql_install_db is available at
db_1         | https://mariadb.com/kb/en/installing-system-tables-mysql_install_db
db_1         | You can find the latest source at https://downloads.mariadb.org and
db_1         | the maria-discuss email list at https://launchpad.net/~maria-discuss
db_1         |
db_1         | Please check all of the above before submitting a bug report
db_1         | at http://mariadb.org/jira
version: '3.1'

services:

  wordpress:
    image: wordpress
    restart: always
    ports:
      - 8080:80
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: user
      WORDPRESS_DB_PASSWORD: pw
      WORDPRESS_DB_NAME: db_name
    volumes:
      - /c/Users/ユーザー名/work/wordpress:/var/www/html

  db:
    image: mariadb
    restart: always
    environment:
      MYSQL_DATABASE: db_name
      MYSQL_USER: user
      MYSQL_PASSWORD: pw
      MYSQL_RANDOM_ROOT_PASSWORD: '1'
    volumes:
      - /c/Users/ユーザー名/work/db:/var/lib/mysql
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?