Edited at

EC2でdocker-composeを利用しWordPressインストール

More than 1 year has passed since last update.

EC2で5分でWordPressを構築します。

以下の手順で作成します。


  1. docker install

  2. docker-compose install

  3. 起動ファイル作成

  4. WordPress起動

※EC2の起動は省略します。

※利用するAMIはAmazon Linuxです。


docker install

yumでサクッとinstall


__| __|_ )
_| ( / Amazon Linux AMI
___|\___|___|

https://aws.amazon.com/amazon-linux-ami/2016.09-release-notes/
$ sudo su
# yum install -y docker


docker-compose install

公式を参照にinstall

# curl -L "https://github.com/docker/compose/releases/download/1.8.1/docker-compose-$(uname -s)-$(uname -m)" > /usr/local/bin/docker-compose

% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 600 0 600 0 0 684 0 --:--:-- --:--:-- --:--:-- 684
100 7798k 100 7798k 0 0 636k 0 0:00:12 0:00:12 --:--:-- 1132k
# chmod +x /usr/local/bin/docker-compose
# /usr/local/bin/docker-compose -v
docker-compose version 1.8.1, build 878cff1


起動ファイル作成

公式を参照に起動ファイル(docker-compose.yml)作成

# cat <<EOF > docker-compose.yml

version: '2'

services:
db:
image: mysql:5.7
volumes:
- "./.data/db:/var/lib/mysql"
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress

wordpress:
depends_on:
- db
image: wordpress:latest
links:
- db
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_PASSWORD: wordpress
EOF


WordPress起動

docker serverを起動

# service docker start

Starting cgconfig service: [ OK ]
Starting docker: . [ OK ]

WordPress起動

# /usr/local/bin/docker-compose up -d

Creating network "ec2user_default" with the default driver
Pulling db (mysql:5.7)...
5.7: Pulling from library/mysql
386a066cd84a: Pull complete
827c8d62b332: Pull complete
de135f87677c: Pull complete
05822f26ca6e: Pull complete
63ddbddf6165: Pull complete
15fe0fbc587e: Pull complete
93e74acdb291: Pull complete
11c2df82e984: Pull complete
d42a9e6a85c8: Pull complete
aec13cb17a3d: Pull complete
d74f62564a6f: Pull complete
Digest: sha256:5bfc6c2a3adbcb9aad7a111b18a2a8defec59d4284063a0f7c84ea44a81a365f
Status: Downloaded newer image for mysql:5.7
Pulling wordpress (wordpress:latest)...
latest: Pulling from library/wordpress
386a066cd84a: Already exists
269e95c6053a: Pull complete
6243d5c57a34: Pull complete
872f6d38a33b: Pull complete
e5ea5361568c: Pull complete
f81f18e77719: Pull complete
f9dbc878ca0c: Pull complete
195935e4100b: Pull complete
c047d6392f67: Pull complete
6d5afcbf41ee: Pull complete
bbe672c318f3: Pull complete
c015a3b2e201: Pull complete
6eb6d78a72af: Pull complete
ff76b754471b: Pull complete
a95632e24e80: Pull complete
863f9b4c6b73: Pull complete
8b02b7760190: Pull complete
58725be21a3b: Pull complete
8e7c95e1471c: Pull complete
Digest: sha256:f5e8cafe19d2ff082445960169ceaf7eac01a0669927f963896d6572c15bd607
Status: Downloaded newer image for wordpress:latest
Creating ec2user_db_1
Creating ec2user_wordpress_1
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e40f26602c6f wordpress:latest "docker-entrypoint.sh" About a minute ago Up About a minute 0.0.0.0:8000->80/tcp ec2user_wordpress_1
5e9da95a9d9f mysql:5.7 "docker-entrypoint.sh" About a minute ago Up About a minute 3306/tcp ec2user_db_1

ブラウザで8000ポートにアクセスでWordPressの初期設定画面が確認できます。