- Docker for Mac and GUI applications. 31 Jul 2016 #Docker. A quick guide on how to run containers requiring a GUI with Docker for Mac and XQuartz. This guide is assuming the following: OS X 10.11.5 (El Capitan) Docker for Mac 1.12 stable. XQuartz 2.7.10 beta 2. Jessie Frazelle’s Firefox Dockerfile.
- Docker on El Capitan. Apr 1, 02:35 PM. Categories WebDev. Docker is a tool that makes containers: local environments in which you can run certain versions of software (I haven’t explained this very well). This means that you can, for example, set up a local webserver with the specific versions of PHP, Apache and MySQL.
- I am using Docker for Mac and wish to create Docker image running a Mac El Capitan with my development env. I am not finding any resources on this. All I see is Linux installations. On Linux I saw things as simple as: FROM sciensa2/docker-java8 RUN apt-get update RUN apt-get install -y wget unzip libgtk2.0-0:amd64 libxtst6.
環境
OSX El Capitan
docker Version 1.13.1
Docker for Macをインストールする
wordpress用のディレクトリを作る
Get menu, photos and location information for El Capitan Restaurant in Chicago, IL. Or book now at one of our other 11334 great restaurants in Chicago. If you want to install Docker for Mac for free, your computer must have been manufactured in 2010 or later and needs to be running macOS El Capitan 10.11 or higher. If you have Windows 7, Windows 8, or an older Mac, you need to install Docker Toolbox instead of Docker for Windows or Docker for Mac. This download will install the required Hyper.
docker-composeの準備をする
docker-compose.ymlをつくる
container名をつける
上記のようにすることで任意のcontainer名がつけられる。
何も指定しないとwp_wordpress_1・wp_db_1などという名前にされてしまってわかりづらくなるので、指定するのがおすすめ。
dbとWordPressで別々のcontainerが必要になるので、dbの方は末尾に-db
をつけるなどして区別すると良い。
同様にしてnetwork名も明示的につけると良い。
開発を行うディレクトリをcontainerに同期する
Dockerでは、ローカルPCのディレクトリをcontainer内のディレクトリに同期(マウント)できる。このときマウントされる領域を volume と呼ぶ。
ローカル環境でwordpressを編集しながらcontainerに同期させるためには、以下のように記述する。
アクセスポートを変更する
デフォルトで'8000:80'
になっているので、すでにlocalhost:8000
を使っている場合は変更する。
ポートが重複しているとbuild時にエラーが出てbuildが止まる。
buildが途中で止まってしまったときは、妙なcontainerが出来ていたりするので下記を参照にしてまっさらにしてやり直す。
環境変数は.envにまとめて読み込む
以下のように記述することで外部の.envファイルを読み込むようにできる。
全体のサンプルは下記。
docker-compose.ymlを使ってbuildする
buildのコマンドを叩く
こんな感じのメッセージが出て、wordpressがbuildされる。
imageが作られたことを確認する
※わたしはwordpress 4.7.2-php7.1-apacheも使っているため3つあります。
containerが立ち上がったことを確認する
起動していないcontainerも含めて一覧を見るコマンドはこちら。意図したcontainerが立ち上がっていなかったら、このコマンドでbuildが失敗していないか確認する。
localhost:8000にアクセスして確認する

localhost:{設定したアクセスポート番号}
をURLに入力してアクセスすると、WordPressの初期設定画面が出てくる。
何て簡単なのでしょう...!
buildに失敗したとき
関連するcontainerを停止した上に削除する
失敗したconatainerとnetworkが残っていないか確認する
何らかの原因でdocker-compose down -v
しても失敗したcontainerや不要なnetworkを削除できないときは、以下のコマンドで対処する。
1.不要なcontainerが存在するが、起動はしていなかった場合
2.不要なcontainerが存在し、起動している場合
3.不要なnetworkが残っている場合
Docker Os X El Capitan
参考にさせていただいた記事
Docker El Capitan Download
https://docs.docker.com/compose/wordpress/
https://tech.recruit-mp.co.jp/infrastructure/post-11266/
http://qiita.com/muk-ai/items/3350122d9e09473723c6