使用EC2并利用docker-compose来安装WordPress

我会在EC2上用5分钟搭建WordPress。
按照以下步骤进行创建。

    1. 安装Docker

 

    1. 安装Docker Compose

 

    1. 创建启动文件

 

    启动WordPress

※我们将省略启动EC2。
※我们将使用Amazon Linux作为AMI。

安装Docker

在yum里快速安装


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

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

安装Docker Compose

按照公式参考进行安装

# 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服务器

# 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的初始设置界面。

广告
将在 10 秒后关闭
bannerAds