LoginSignup
4
3

More than 5 years have passed since last update.

Docker for Mac に Word Pressを導入

Last updated at Posted at 2017-04-25

Docker for Mac インストール:ferry:

Macアプリをダウンロード(Stable channelの安定版)
https://docs.docker.com/docker-for-mac/install/

インストール
スクリーンショット 2017-04-23 17.58.39.png

アプリケーションから選択
スクリーンショット 2017-04-23 18.45.45.png

Next!
スクリーンショット 2017-04-23 17.58.58.png

OK!
スクリーンショット 2017-04-23 17.59.08.png

ツールバーの上に表示される
スクリーンショット 2017-04-23 17.59.26.png

ターミナルからDockerのバージョン確認

$ docker --version
Docker version 17.03.0-ce, build 60ccb22

$ docker-compose --version
docker-compose version 1.11.2, build dfed245

$ docker-machine --version
docker-machine version 0.10.0, build 76ed2a6

MySQLを設定

MySQLのインストール

$ docker run --name test_wordpress_db -e MYSQL_ROOT_PASSWORD=pass -d mysql

Unable to find image 'mysql:latest' locally
latest: Pulling from library/mysql
6d827a3ef358: Pull complete
ed0929eb7dfe: Pull complete
03f348dc3b9d: Pull complete
fd337761ca76: Pull complete
7e6cc16d464a: Pull complete
ca3d380bc018: Pull complete
23c12ddae61f: Pull complete
14553c628372: Pull complete
c9445076b453: Pull complete
8feabd297745: Pull complete
835cd3cde5d5: Pull complete
Digest: sha256:3ea679cbde178e346dcdeb538fd1ea4f1af256020ebeb464ccb72a1646a2ba6d
Status: Downloaded newer image for mysql:latest
1ea5904d998eee2f1c78db059f6eca30a2c5aecc0c14010598bee34c6073cc55

インストール確認

$ docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
1ea5904d998e        mysql               "docker-entrypoint..."   36 seconds ago      Up 35 seconds       3306/tcp            test_wordpress_db

WordPress起動

$ docker run --name test_wordpress --link test_wordpress_db:mysql -p 8080:80 -d wordpress

Unable to find image 'wordpress:latest' locally
latest: Pulling from library/wordpress
6d827a3ef358: Already exists
87fe8fbc743a: Pull complete
f6d1a8d304ab: Pull complete
caf3547d9b73: Pull complete
1004db2760ff: Pull complete
66e2d66a547e: Pull complete
bbfaa62c234a: Pull complete
19ce8807f4d1: Pull complete
65dc0142d59b: Pull complete
a95f4fa43ae2: Pull complete
f4edd48c3730: Pull complete
d58fc629c9d1: Pull complete
c75a71ebb7f4: Pull complete
92667bd16dd2: Pull complete
158b965a06fc: Pull complete
cdbb556ec528: Pull complete
79dd5209b5a0: Pull complete
c390e42be10f: Pull complete
Digest: sha256:980dcdf0c66aa863f309f1d2bb618f4981dcb926a43bc0f65f5d2a0c3be81149
Status: Downloaded newer image for wordpress:latest
dcdc5a80421a9e49875c65d2a3ffa65b3461634abb8f491a6405d2135be74a1e

接続確認

http://localhost:8080/にアクセス

スクリーンショット 2017-04-24 2.27.30.png

これだけで設定をいじれる

スクリーンショット 2017-04-26 1.13.23.png

ローカルからファイルを編集するのための設定

WordPressのディレクトリ確認

以下を実行すると/var/www/htmlの中に入るので、lsするとindex.phpなどWordPressのファイル群がある

$ docker exec -it test_wordpress bash

root@ec40bf496724:/var/www/html#

ローカルと同期する

docker runのオプションでローカルのディレクトリと同期するコマンドがあるので、そちらを使う。
一旦wordpress の Container と Image を削除。

起動中のコンテナの確認
$ docker ps
コンテナの停止
$ docker stop {コンテナID}
停止中のコンテナ確認
$ docker ps -a
コンテナの削除
$ docker rm {コンテナID}
コンテナが消えていることを確認
$ docker ps -a
イメージの確認
$ docker images
イメージの削除
$ docker rmi {イメージID}
イメージのが消えている事を確認
$ docker images

ローカルの指定したディレクトと/var/www/htmlの中身を同期するオプションを付けてWordPressを起動する

$ docker run --name test_wordpress --link test_wordpress_db:mysql -p 8080:80 -v /{ローカルのパス}:/var/www/html -d wordpress

これで同期されているので、ローカルにさっきのファイル群が見れるようになる。
wordpressが立ち上がっていれば、ローカルのファイルを編集するだけで同期される。

参考

4
3
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
4
3